wood burning stoves 2.0
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes About <c:set target> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "About <c:set target>" Watch "About <c:set target>" New topic

About <c:set target>

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

I've found this one. Somebody please confirm it! Please!
For c:set target -
1. object should be available already in any of the four scopes. otherwise throws exception
2. supports only for Map and Bean objects
3. target can have EL expressions or scriptless
4. If target attribute is null it throws exception
5. Removal: if the value is set null for the property then it works this way
5.1 if target is map then key is removed from the map object
5.2 if target is bean then property value is set to null.
6. Add: If the target is map object then if
6.1 property is new then it is added to the map
6.2 if the key already exist then it overwrites.


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Ankit Garg

Joined: Aug 03, 2008
Posts: 9452

Abimaran please tell the question's source...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

It's not a question. I just got it, when I searched for more explanation for this topic. It's from here. And please confirm it, whether it's correct or not. I'm preparing for exam.
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper

Joined: Apr 07, 2010
Posts: 2040

Hi Abimaran,

I've found this one. Somebody please confirm it! Please!

Yes, those statements are all correct.

The explanation is found in the jstl1.1 specs:

4.3 <c:set>
...left out syntax 1 & 2...
Syntax 3: Set a property of a target object using attribute value
<c:set value="value" target="target" property="propertyName"/>
Syntax 4: Set a property of a target object using body content
<c:set target="target" property="propertyName">
body content

Attribute target accepts (rte) RunTimeExpressions. Target object whose property will be set. Must evaluate to
a JavaBeans object with setter property property, or to a java.util.Map object.

Null & Error Handling
Syntax 3 and 4: Throw an exception under any of the following conditions:
- target evaluates to null
- target is not a java.util.Map object and is not a JavaBeans object that supports setting property property.

If value is null
- Syntax 3:
- if target is a Map, remove the entry with the key identified by property.
- if target is a JavaBean component, set the property to null.

Syntax 3 and 4:
- If the target expression evaluates to a java.util.Map object, set the value of the element associated with the key identified by property. If the element does not exist, add it to the Map object.
- Otherwise, set the value of the property property of the JavaBeans object target. If the type of the value to be set does not match the type of the bean property, conversion is performed according to the conversion rules defined in the expression language (see Section A.7). 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. A failure of these conversion rules to determine an appropriate type coersion leads to a JspException at runtime.

Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Thanks Frits.
I agree. Here's the link: http://aspose.com/file-tools
subject: About <c:set target>
It's not a secret anymore!