This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About <c:set target>

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran please tell the question's source...
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 2418
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic