File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "About <c:set target>" Watch "About <c:set target>" New topic
Author

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.


Thanks!


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

Joined: Aug 03, 2008
Posts: 9280
    
  17

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
Bartender

Joined: Apr 07, 2010
Posts: 1521
    
  22

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
</c:set>

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.

Description
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.

Regards,
Frits
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>
 
Similar Threads
HFSJ page- 395
c:set tag not clear
c:set for a Map
SCWCD Certified Today - 89%
target attribute of c:set