This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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 ]
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.
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.