wood burning stoves 2.0*
The moose likes Struts and the fly likes iterating over a user defined class object using logic iterate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "iterating over a user defined class object using logic iterate" Watch "iterating over a user defined class object using logic iterate" New topic
Author

iterating over a user defined class object using logic iterate

san geetha
Ranch Hand

Joined: Sep 07, 2004
Posts: 44
I have a list of user defined objects to iterate over using logic:iterate. The values of the object are being displayed in a text box so that the users can update the values. After th user updates the value in the front end,I am not able to retrieve the corresponding line item modified.

Assuming there are 5 line items being displayed using logic:iterate over a list (list contains objects of user defined class), if the user needs to update a value in thatz present in the 3rd line item, using an id field(property in the user defined class), iam able to determine the row. but in the action class when the form bean's object is accessed the 1sr line item's values are retrieved rather than the 3rd.

Kindly help.

Logic - iterate code
<logic:iterate id="custConId" name="WSREditFormBean" property = "custConcerns" type="bean.ConcernsVO">
...
...
<bean:define id= "conId" name="custConId" property="concernId" />
...
<html:text indexed="true" name="custConId" property="concernDesc" styleClass="tbclrwhite" />
...
...
</logic:iterate>
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
you may want to have a unique id associated with each line item (another property inside the user-defined object) rather than using the index of the list. especially when line items can be removed or added that can throw the index out of whack going from JSP into form then to your action. -/a


-/a<br />certified slacker...yes, my last name is 'do' - <a href="http://www.luckycouple.com" target="_blank" rel="nofollow">luckycouple.com</a>
san geetha
Ranch Hand

Joined: Sep 07, 2004
Posts: 44
I do have an unique id associated with each line item... (ie) concernId
My problem is if i want to update a value in the 3rd LItem, then iam not able to get the handle to the altered LItem. In the action class, i have the formbean's object... but it always contains the value of the first LItem.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
i see what the problem is. you must set your value objects values into the ActionForm that is mapped that that action, not putting it into a "formbean". (unless your WSREditFormBean IS the name of the form you mapped that action to, in which case i misunderstood).

you then need to access the line items by iterating through the "MyForm.map.myItems". in your case, you'll need to do the following:

1. form-bean definition must contain
<form-bean name="ConcernForm".../>
<form-property name="custConcerns" type="bean.ConcernVO[]"/>

2. your action execute method then populates the properties using form.set("custConcerns",ConcernsVO[])

3. in your logic:iterate, you need to access the form by something like...
<logic:iterate id="custConId" name="ConcernForm.map.custConcerns" property = "custConcerns" type="bean.ConcernsVO">
 
jQuery in Action, 2nd edition
 
subject: iterating over a user defined class object using logic iterate
 
Similar Threads
Regarding Logic iterate
Database driven dynamic radion buttons
Iterator in struts
I need help, with logic:iterate in HashMap
Editing and submitting multiple records