• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts Iterate tag, issue in populating form bean values

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.


Thanks in Advance.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,

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.

JSP Code:
------
<nested:iterate name="spreadActionForm" id="spreadItem" property="spreadList" >
<tr>
<td>
<html:text name="spreadItem" property="rating" indexed="true" />
</td>
<nested:iterate name="spreadItem" property="profileCompoList" id="profileComp">
<td>
<nested:text name="profileComp" property="value" indexed="true" />
</td>

</nested:iterate>

</tr>
</nested:iterate>

-------------------------------------------
ActionForm :
--------------

public void setSpreadList(List spreadsList){ this.spreadList = spreadsList;}
public List getSpreadList(){ return this.spreadList;}
private List spreadList;

public Profile getSpreadItem(int index){
if(this.spreadList == null){ this.spreadList = new ArrayList();}
return (Profile) spreadList.get(index);}



Profile class:
--------------
public ArrayList getProfileCompoList(){ return this.profileCompoList; }
public void setProfileCompoList(ArrayList profiles){ this.profileCompoList = profiles ; }
private ArrayList profileCompoList;

public String getRating() { return rating; }
public void setRating(String rating) { this.rating = rating; }
private String rating;

public ProfileComponent getProfileComp(int index){return ((ProfileComponent)profileCompoList.get(index));}

ProfileComponet class:
-------------------
public double getValue() { return value; }
public void setValue(double value) {this.value = value; }
private double value;
-----------------------------


Thanks so much in Advance.
 
Narasimha Rao B.
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any help please.

Thanks.
 
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

- Brent
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic