aspose file tools*
The moose likes Struts and the fly likes logic:iterate : Problem while populating collection from inside Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "logic:iterate : Problem while populating collection from inside" Watch "logic:iterate : Problem while populating collection from inside" New topic
Author

logic:iterate : Problem while populating collection from inside

Aprameya Karthik
Greenhorn

Joined: Nov 09, 2006
Posts: 3
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;
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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.


Merrill
Consultant, Sima Solutions
Aprameya Karthik
Greenhorn

Joined: Nov 09, 2006
Posts: 3
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

Joined: Feb 15, 2005
Posts: 4864
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.
 
Consider Paul's rocket mass heater.
 
subject: logic:iterate : Problem while populating collection from inside