Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSTL (c:set)

 
Steven Colley
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • 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;
 
Connie Ky Leung
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic