• 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

logic:iterate : Problem while populating collection from inside

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using a form that contains a collection of objects. I am using logic:iterate and html:text to iterate over it.
I use the same form for editing and submitting.
When I come to the editing page, it is reading the values from the collection of objects correctly. But when I change values and resubmit, the collection is returned as empty in my action.
I am attaching action, form and jsp here. Any help will be greatly appreciated.

Thanks in advance
Karthik

The jsp initially populates with 6 rows as expected from the following code

PopulateJSPAction{
for (int i = 0; i < 6; i++) {
ProfessionalServiceDTO professionalServiceDTO = new ProfessionalServiceDTO();
professionalServiceCollection.add(professionalServiceDTO);
}
}
JSP :
*************
<html:form name = "editHCFA1500Form".....>

<logic:iterate name = "editHCFA1500Form" id = "serviceCollection" property="professionalServiceCollection" type="com.h2hsolutions.database.hcfacms.beans.ProfessionalServiceDTO">
<html:text name = "serviceCollection" property="serBegDate" size="4"/>
</html:form>

Form Bean:
*******************

public class EditHCFA1500Form extends ActionForm

{
/**
*
*/
private static final long serialVersionUID = 1L;
private ArrayList professionalServiceCollection = new ArrayList();

public ArrayList getProfessionalServiceCollection() {
return professionalServiceCollection;
}

public void setProfessionalServiceCollection(
ArrayList professionalServiceCollection) {
this.professionalServiceCollection = professionalServiceCollection;
}
//There is also an indexed getter method as reqd by struts
public ProfessionalServiceDTO getProfessionalServiceCollection(int index) {
return (ProfessionalServiceDTO)professionalServiceCollection.get(index);
}

Action Class:
**********************
execute(....){

ArrayList professionalServiceCollection = editHCFA1500Form.getProfessionalServiceCollection();

System.out.println("Collection size = "+professionalServiceCollection.size());
}


The output is coming as Collection size = 0;
 
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 will need to use "indexed properties" to accomplish this. There is a bit of a learning curve in using indexed properties. I'd suggest you start with reading the following two articles:

http://wiki.apache.org/struts/StrutsCatalogLazyList
http://struts.apache.org/1.2.9/faqs/indexedprops.html

I will give you one hint: You'll need to create an "indexed getter" for the professionalServiceCollection attribute in your ActionForm.
 
Aprameya Karthik
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have given an indexed getter method in the form bean

public ProfessionalServiceDTO getProfessionalServiceCollection(int index) {
return (ProfessionalServiceDTO)professionalServiceCollection.get(index);
}

But its still not working.
Is this method wrong?

Thanks
Karthik
 
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
Did you read the articles? An indexed getter is not the only change you need to make to your application. You must change the <logic:iterate> tag as well as the <html:text> tag. Furthermore, if your ActionForm is in request scope, you will also have to add "lazy initialization" behavior to your indexed getter.

If you've read the articles and are still having problems, we're happy to help, but you'll have to give us an exact description of the error you're getting along with the relevant parts of your JSP and ActionForm.
 
reply
    Bookmark Topic Watch Topic
  • New Topic