Hi, my problem is not to show up the information,the logic:iterate inside logic:iterate works fine, the problem is to get the information again by tyhe form. ------ <logic:iterate name="calificacionForm" id="calificacion" property="matriculas" indexId="index">
I believe Brent's first solution should work. You should also remove indexed="true" from the <html:text> tag.
Using the indexed attribute works OK for simple forms with only one array list, but for multiple arrays, I've found that it's better just to take control of creating the property name so that you're sure you get a property name that will correctly reflect the structure of the data. [ March 22, 2006: Message edited by: Merrill Higginson ]
Hey thanks for the help,I tried that way, but there is another problem now: it cant populate the form because of this... --- java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 java.util.ArrayList.RangeCheck(ArrayList.java:547) java.util.ArrayList.get(ArrayList.java:322) org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:521)org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254) org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482) org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525) javax.servlet.http.HttpServlet.service(HttpServlet.java:709)javax.servlet.http.HttpServlet.service(HttpServlet.java:802) -----
I have to mention Im working with ArrayList, and just like before, it shows the information, but after the submit, this exception. I cant find the reason for an IndexOutofBounds...
Ok. So according to your code and your explanation, CalificacionForm is structured as follows:
Am I right with that? Seems kinda off from what you've been describing. Can you post the java file that is handling the submit, please? I suspect it's attempting to access an empty ArrayList.
Joined: Feb 15, 2005
Any time you use indexed properties you run into a problem when the ActionForm is in request scope. You build this structure of arrays within arrays, and everything works fine to display the page, but what happens when you're ready to submit the form? Since the ActionForm is in request scope, that bean as well as any objects you put in it is completely gone! Struts instantiates a new bean for you, but the newly instantiated bean doesn't have the array of arrays that the old one had. That's why you're getting the array index error: You're expecting a structure to exist within your ActionForm that no longer exists.
What to do?
The easiest way to solve this problem is simply to change the scope of your ActionForm from request to session. If the bean is in session scope, the structure you created before the form was displayed will still be there when the form is submitted.
If for some reason you don't want to put the ActionForm in session scope, you will have to rebuild the structure prior to the setters being called by struts. One way to do this is to override the reset() method in ActionForm. Since this method is called by Struts before it calls the setters, it's a good place to put code to rebuild the structure of the ActionForm.
Another method is "lazy initialization", which means you put code in the getters to instantiate objects if they don't exist. Here is a link explaining that method [ March 23, 2006: Message edited by: Merrill Higginson ]