wood burning stoves 2.0*
The moose likes Struts and the fly likes forbean's getmethod never called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "forbean Watch "forbean New topic
Author

forbean's getmethod never called

Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

http://faq.javaranch.com/java/IndexedProperties

In the above link of javaraunch FAQs, the below method is never called from any class still useful, May i know how this method is being called by struts. And, 1/ is it neccessary to use this kind of methods to maintain indexed properties?

2/does this method only works when logic:iterate has "id" attribute with the same name?

3/ and it seems there is no use of using "id", indexed="true" without useing this method.


[ October 17, 2007: Message edited by: Rauhl Roy ]
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
hmmm...that method looks familiar. If you are using code like the sample, then this method will be called when your form is submitted. I added some logging to the code to give a better feel of what is going on behind the scenes. When I click the submit button on the save page, here is what it kicked out:


(*1*) A brand new OrderIndexedForm instance is created
(*2*) The method getOrderItem() is called with various index values
(*3*) On the first call, orderList is null so it is initialized
(*4*) A total of 5 new OrderItem instances are created and added to orderList
(*5*) Execution finally gets to SaveOrderIndexedAction after the form has been populated.

Note that getOrderItem() is called twice for each index. Why is that? Well first look at the JSP and noticed that each item has two indexed fields:


When the form is submitted this basically translates into the following two method calls:


Why the indexes come is a rather random order is something that I do not really know. The code is setup to handle it whether the first index is 4 or 0.

- Brent
Rauhl Roy
Ranch Hand

Joined: Aug 01, 2006
Posts: 401

Thnks Mr. Brent Sterling for your reply, i still need your clarification.

So, We dont need to call the get method mentioned in the form bean? And if we use 'id' in <logic:iterate> struts framework automatically checks for that method and calls it?
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Ummm...you can call me Brent. Have you read this page (four or five times)?
http://struts.apache.org/1.x/struts-taglib/indexedprops.html

Right, you never need to write code to call your indexed get property. The innards of Struts will do that for you. It took me a while to figure out that there are two sides to using indexed properties: displaying the page with the values from the form and submitting the page so that it populates the form. Using the correct id attribute of the iterate tag is what ties the two together.

- Brent
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: forbean's getmethod never called
 
Similar Threads
Struts1: Nested/Indexed properties issue
Check box and Indexed properties
Indexed Properties Example
html:hidden within logic:iterate
How to take dynamic values of textboxes to Action class