Hi, I am using the iterate tag to populate the jsp page from formbean, it is working fine, but when the user modifies the values in the jsp page, when priting the values in the form bean it is printing the old values(intial values that are populated the jsp page) instead of the modified values in jsp page.
My JSP code looks like, ------------ <nested:iterate id="spreadDetails" name="limitSpreadActionForm" property="spreadList" type="com.code.ProfileComponent"> <tr><td> <nested:text name="spreadDetails" property="value" /> </td> </tr> </nested:iterate> --------- In the JSP page, at the top formbean is defined as - 'limitSpreadActionForm', this formbean has a property named - 'spreadList', which is of type ArrayList, this ArrayList contains the Objects of type 'ProfileComponent', the 'ProfileComponent' class has a property name 'value'
When i run the code in debug mode, in BeanUtils.setProperty, method displays the values correctly(i.e. Modified values in the JSP page), but when i try to print the values in the ActionForm class, only the old values are printing, not the user modified values.
You need to use indexed properties for this. The nested:text tag does the JSP part automatically, but you still need to create an indexed getter in your ActionForm. Specifically, you'll need a method named getSpreadDetails that takes an integer as a parameter and returns a single ProfileComponent for that index in the list. If your ActionForm is in request scope, you will need to give the method lazy initialization behavior. All of this is explained in much greater detail in question 6 of the JavaRanch Struts FAQ
Thanks so much for your inputs, i have seen your many postings and got the good information, still i have some issues, it would be great if you can help. My issue is, i can display the values in the jsp page, but when i try to submit the page, modified values are not populating to the form bean, instead old values are populating.
My code details are -
In my Action class, i have a ArrayList, which holds list of 'Profile', the 'Profile' Class has one property name 'Rating' and a collection of 'ProfileComponent' and 'ProfileComponent' has a property named 'Value'. My requirement is loop through top ArrayList and display one row each for one ArrayList element, and in each row display first 'Rating' and then loop through collection of 'ProfileComponent' and display the property 'Value'. The display part is fine, but when the user modifies the 'Rating' or 'Value' (of 'ProfileComponent'), the modified 'Rating' values are reflecting in ActionForm bean, but the modified 'Value' are not reflecting in ActionForm bean.
I have never used the nested tags. I looked at your code and nothing really jumped out at me. I take it that you have your action configured to use session scope. I would try to set breakpoints in all your get and set methods to figure out what is being called. I have used indexed properties in about 20 pages and only 1 or 2 of them worked the first time. Probably only half of them were working on the 10th try.
Joined: Feb 15, 2005
When using indexed properties and going more than one level deep, I have found that it's best not to use nested tags or indexed="true" but to manually construct the name of the property to be sure that the indexing is correct. Here's how I'd do it:
If your web application is a servlet Version 2.4 application, you can use EL expressions as I've done above. Otherwise, you have to either use the EL version of the Struts tags or use a scriptlet instead of EL expressions. [ September 16, 2007: Message edited by: Merrill Higginson ]
subject: Struts Iterate tag, issue in populating form bean values