Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

iterating over a user defined class object using logic iterate

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
san geetha
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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">
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
    Bookmark Topic Watch Topic
  • New Topic