| Author |
problem in understanding jstl set tag
|
sangeeta kapoor
Ranch Hand
Joined: Jun 15, 2004
Posts: 70
|
|
HF page 446 "In the <c:set> tag, the target attribute in the tag seems like it should work just like "id" in the <jsp:setProperty>, but it doesn't work that way" But there is no "id" in <jsp:setProperty" . Is it talking about <jsp:useBean> "With the target attribute, you do not type in a String literal that represents the name under which the attribute was bound to page,scope etc" What does this mean? I tried the following Person.java JSP This does work fine. But i am using the "id" in <jsp:useBean> And if it really is <jsp:useBean> above instead of <jsp:setProperty> , how does this work. Also What are the other ways in which a bean can be created and given as a value to "target" Page 447 6th Bullet point If you put in a String literal that represents the "id" name of the bean or Map, it won't work. In other words , "target" is not for the attribute name of the bean or Map-its for the actual attribute object. What is the difference between attribute object and attribute name if I say <% com.Person p = new com.Person(); request.setAttribute("person", p); %> then in this case is "person" a attribute name or object? I think it's a name which represents an object p. Then how can we differentiate between the two. Moreover on the next page to which the request is submitted I only have access to "person", I can't get "p" directly. Plz help me understand this.
|
 |
Nitish Bahadur
Ranch Hand
Joined: Aug 25, 2003
Posts: 118
|
|
You are right. The id in <jsp:setProperty> is the <jsp:useBean> 'id'. The <c:set> target attribute does not allow a string literal "person". If it did allow the string literal, then how would the <c:set> know that the author of the JSP page really wanted a 'person object' and not string literal "person" string. Attributes have names and values. The name is a key, similar to Map keys, and the value is a java.lang.Object. "person", in your example, is the Attribute name, and the object referenced by "p" is the Attribute value.
|
 |
Francois Roland
Ranch Hand
Joined: Jul 24, 2003
Posts: 34
|
|
About your question about the difference between attribute object and attribute name. What you object (or instance, call it the way you like) is is really just no more than a chunk of data stored on the heap. This is what you create when you type new com.Person(). In your code, you decided to store this object in a local variable you called p. One line later, you put the content of the p variable into your request attributes collection (yes, you can think of this as a java.util.Map). So there is really no reason you can get a direct acces to you p variable by any other mean than a scriptlet (remember that all scriptlets of the page are put into the same and unique method when you JSP is translated). In fact, you could have written something like this:
|
--
Brown belt on KnowledgeBlackBelt.com.
|
 |
 |
|
|
subject: problem in understanding jstl set tag
|
|
|