• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSTL (c:set)

 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I got this question:

Which of the following are invalid uses of the <c:set> action? (Choose three.)

1- <c:set scope="page">value</c:set>
2- <c:set value="value" var="${myVar}" />
3- <c:set var="myVar" scope="${scope}">value</c:set>
4- <c:set target="${myTarget}" property="myProp">propValue</c:set>

5- <c:set value="${myVal}" target="myTarget" property="${myProp}" />

With the following answer for the 5th option:

"5 is also valid syntax. Value, target, and property are set as attributes, with the values for value and property coming from EL expressions, which is legal."

i guess it�s wrong.

1- "property" attribute does NOT take a "request-time expresion".
2- IT�s MANDATORY for "target" attribute to be a request-time expression.

am i wrong?

Tks;
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Felipe Pittella:
Hi,

I got this question:

Which of the following are invalid uses of the <c:set> action? (Choose three.)

1- <c:set scope="page">value</c:set>
2- <c:set value="value" var="${myVar}" />
3- <c:set var="myVar" scope="${scope}">value</c:set>
4- <c:set target="${myTarget}" property="myProp">propValue</c:set>

5- <c:set value="${myVal}" target="myTarget" property="${myProp}" />

With the following answer for the 5th option:

"5 is also valid syntax. Value, target, and property are set as attributes, with the values for value and property coming from EL expressions, which is legal."

i guess it�s wrong.

1- "property" attribute does NOT take a "request-time expresion".
2- IT�s MANDATORY for "target" attribute to be a request-time expression.

am i wrong?

Tks;




After going over JSTL specification and HFSJ regarding <c:set>, I believe the answers to this question are 1,2, 3 and 5.

5 is invalid because the value of target is a string literal. Its value is EL expression, <%= %> or <jsp:attribute> that evaluats to a Map object or a Java bean.

Please correct me if I am wrong.
 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI Connie,

I guess that the only one correct is the option 4 in this case.

1 - if there is "scope" attribute, so is mandatory to have "var" or "target" attribute as well.
Error rg.apache.jasper.JasperException: Validation error messages from TagLibraryValidator for : Illegal scope attribute without var in "core:set" tag.

2 - wrong, "var" attribute cannot take request-time expressions.

3 - wrong, "scope" attribute cannot take request-time expressions as well.
Error rg.apache.jasper.JasperException:Validation error messages from TagLibraryValidator for :Invalid "scope" attribute in "core:set" tag.

4- OK

5- Error , target must have a request-time expression.


Tks Connie
 
And then we all jump out and yell "surprise! we got you this tiny ad!"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic