aspose file tools*
The moose likes JSP and the fly likes jsp:setProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:setProperty" Watch "jsp:setProperty" New topic
Author

jsp:setProperty

Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 245
Can someone please explain me what exactly happens with this jsp?
<jsp:useBean id="aaa" scope="request" class="com.lll.aaa"/><jsp:setProperty name="aaa" property="*"/><jsp:getProperty name="aaa" property="xml"/>
Dominic Paquette
Ranch Hand

Joined: Dec 13, 2002
Posts: 64
Hi,
What's hapenning is this:
checks in the session to see if there is an attribute named aaa. If there is one it displays its "xml" property.
If there is no "aaa" attribute in the session, a new instance is created and it's properties will be initialized to the corresponding parameter present in the request(example xml=somevalue). Then it it displays the "xml" property.
Hope this helps
Dominic
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Close, but not quite.
The attribute will be checked for in the request (not the session -- check the scope attribute), and the property will be set regardless of whether the bean instance is newly created or not.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gemini Moses
Ranch Hand

Joined: Jan 04, 2001
Posts: 245
Thanks for your reply.
I am trying to understand existing code in my new project. Can you please make it more simple for me in getting to basic level as to,
Whenever a call is made to this jsp, it is going to call,
from aaa.java class setXML method.
I have aaa.java class with constructor, setXML and getXML methods in it. But when I tried printing some statements in these methods they are not seen in my log file.
Please help me!!
Awaiting fast reply...
Pete Cassetta
Greenhorn

Joined: Feb 13, 2001
Posts: 23
Originally posted by Gemini Moses:
Thanks for your reply.
I am trying to understand existing code in my new project. Can you please make it more simple for me in getting to basic level as to,
Whenever a call is made to this jsp, it is going to call, from aaa.java class setXML method.
I have aaa.java class with constructor, setXML and getXML methods in it. But when I tried printing some statements in these methods they are not seen in my log file.
Please help me!!
Awaiting fast reply...

Let's say this page is aaa.jsp. Now if you load http://www.yourdomain.com/aaa.jsp then there will be no call to setXML() because there is no request parameter named "XML." If, instead, you call it via http://www.yourdomain.com/aaa.jsp?XML="file.xml" then there will be a call to setXML("file.xml").
When you use the wildcard "*" all the request parameters are scanned, and any whose names match those of setters in the bean will cause the setter to be called with the parameter value.
Hope this clarifies somewhat...
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
Let's say this page is aaa.jsp. Now if you load http://www.yourdomain.com/aaa.jsp then there will be no call to setXML() because there is no request parameter named "XML." If, instead, you call it via http://www.yourdomain.com/aaa.jsp?XML="file.xml" then there will be a call to setXML("file.xml").
When you use the wildcard "*" all the request parameters are scanned, and any whose names match those of setters in the bean will cause the setter to be called with the parameter value.

I don't understand this.
Hope this clarifies somewhat...

No not at all, pls. help. How would passing a queryString invoke a mutator ?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Bhushan Jawle:
How would passing a queryString invoke a mutator ?

The following is from the Sun JSP Documentation talking about <jsp:setProperty property="*"/>:
Stores all of the values the user enters in the viewable JSP page (called request parameters) in matching bean properties. The names of the properties in the bean must match the names of the request parameters, which are usually the elements of an HTML form. A bean property is usually defined by a variable declaration with matching getter and setter methods (for more information, see java.sun.com/products/javabeans/docs/).

[ April 22, 2003: Message edited by: Lasse Koskela ]

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:setProperty