This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding c:set tag

 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Regarding <c:set> tag, if the varibale or targeted Map/Bean doesnot exist. Will it create one in default scope. If we donot mention the scope, will it search specified variable in all scopes(page, request, session and application).

Thanks
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it will not search for all the scopes, it will create one in default scope
 
Shrenik Sakriya
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<c:set var="name" scope="session" value="super"/> : In this case the attribute "name" if exists in the session then it will simply replace the value of the attribute , if it doesn't exist then it will add it to the session.


<c:set target="${person}" scope="session" property="name" value="XXXX"/> : In this case of the "person" object doesn't exist in the session then it will trow an exception.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it will create one in default scope

Which is called the page scope.
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ali Gohar:
No, it will not search for all the scopes, it will create one in default scope



At page 445 of HFSJ it says "if you don't specify scope it will start looking in page then request etc"
At page 447 in 2nd question "if you don't use the optional scope attribute in the tag you are using var or target, the container will search scopes in order page, then request....."

Any one can please explain this
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is page 445 talking about ?
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At page 445 of HFSJ it says "if you don't specify scope it will start looking in page then request etc"
At page 447 in 2nd question "if you don't use the optional scope attribute in the tag you are using var or target, the container will search scopes in order page, then request....."

Its about <c:set> tag. These pages discuss <c:set> tag
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it about setting the value to "null" ? If it is, it will then act as removeAttribute. Please confirm.
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satou

Below are the complete texts

Page 445 says
If the value evaluates to null, the variable will be removed!
Imagine that for the value(either in the body of the tag or using the value attribute), you use ${person.dog} evaluates to null(meaning there is no person or person's dog perperty is null), then if there is a variable attribute with a name Fido, that will be removed! (if you donot specify a scope, it will start looking at page, then request etc)


This one seems working like <c:removeAttribute>.

Here comes the confusion one, the text from page 447
If you donot use optional scope attribute in the tag and you are using var of target, the container will search scopes in the order in which you have come to expect-page, then request etc


Please comment

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see. They are referring to page 25 of the JSTL specification.
4.3 <c:set>
Description of Syntax 3 and 4 (which is about using the "target" attribute)

With the exception of a null value, setting a bean property with <c:set> is therefore exactly the same as setting an attribute value of an action using the EL.

It means that, like EL, the target will be looked for in all scopes, like calling PageContext.findAttribute(target). The findAttribute method searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null.
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Satou

One little correction in quote fromage 447

it is var or target not var of target

If you donot use optional scope attribute in the tag and you are using var or target, the container will search scopes in the order in which you have come to expect-page, then request etc
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using the "var" attribute, the default scope will be "page", except when "scope" is not defined and the value is set to null. If you use the "target" attribute, all scopes will be scanned.

<c:set var="name" value="bob"> : name=bob in page scope
<c:set var="name" value=a null value> : name will be removed from all scopes
<c:set target="person" property="name" value="bob"> : person will be searched in all four scopes and when found its name will be set
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic