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 Difference between attribute variables and bean properties 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 "Difference between attribute variables and bean properties" Watch "Difference between attribute variables and bean properties" New topic
Author

Difference between attribute variables and bean properties

Aaron John
Ranch Hand

Joined: May 30, 2005
Posts: 74
What is the difference between attribute variables and bean properties? In HFSJ p 445-446, it explains the <c:set>, where var is used for attribute variables and target is used for bean properties and map values. Aren't attribute variables and bean properties the same thing?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Using "var" would be the same as calling setAttribute. So you could set a value in the session scope, request scope, or any other.
Simply think that it is the same as setAttribute, applied on a scope specified with the "scope" attribute.
For example,
<c:set var="name" scope="session" value="Aaron"/>

You use "property and "target" together, to set a bean's member value, or a Map entry. If the target is a bean, its setter method will be called.
For example, MyBean has a member called "String lastName", with a setter called "setLastName(String)". Using the "target" will call the setter.
If the "target" is a Map, the put(key,value) method will be called, where key is defined by "property" and value by "value".

To sum up:
<c:set var="name" scope="session" value="Aaron"/>
-> same as session.setAttribute("name", "Aaron")

<c:set target="myBean" property="lastName" value="John"/>
-> same as myBean.setLastName("John")

<c:set target="myMap" property="lastName" value="John"/>
-> same as myMap.put("lastName", "John")


[My Blog]
All roads lead to JavaRanch
Aaron John
Ranch Hand

Joined: May 30, 2005
Posts: 74
Thank you very much! I hope I remember that for my upcoming exam.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between attribute variables and bean properties