aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Regarding c:set tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Regarding c:set tag" Watch "Regarding c:set tag" New topic
Author

Regarding c:set tag

Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
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


"Know where to find the solution and how to use it - that's the secret of success."
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
No, it will not search for all the scopes, it will create one in default scope
Shrenik Sakriya
Ranch Hand

Joined: May 07, 2001
Posts: 40
<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.


SCJP1.2 88%<br />SCWCD1.4 89%<br />CCNA 94%
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

it will create one in default scope

Which is called the page scope.


[My Blog]
All roads lead to JavaRanch
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Thanks guys
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

What is page 445 talking about ?
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Is it about setting the value to "null" ? If it is, it will then act as removeAttribute. Please confirm.
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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

Joined: Nov 14, 2005
Posts: 324
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regarding c:set tag