wood burning stoves 2.0*
The moose likes Struts and the fly likes Value not returned to form inside 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 "Value not returned to form inside logic:iterate" Watch "Value not returned to form inside logic:iterate" New topic
Author

Value not returned to form inside logic:iterate

JD Thompson
Greenhorn

Joined: Jun 29, 2006
Posts: 21
Currently, with the referenced code below, the selected value on the page IS NOT being saved on the ActionForm with the property listed. Any ideas as to why? Thanks to all!



<logic:iterate name="ReportListForm" property="reportChosen.groups" id="groups">
<logic:iterate name="groups" property="parms" id="parmValues" >
<c:set var="dataName" value="${parmValues.dataType}" />
<c:if test="${dataName=='multipleSelect'}">
<td>
<html:select indexed="true" size="10" name="parmValues" property="value" multiple="true">

<html ptionsCollection name="parmValues" property="choicesList" />

</html:select>
</td>
</c:if>
</logic:iterate>
</logic:iterate>

terms explained
--------------------------------
ActionForm="ReportListForm"
reportChosen = Report class that stores information
groups = ArrayList property of Group types, property of reportChosen
parms = ArrayList property of Parm types, property of groups
dataType = lets me know which type of html element to created for user input
multipleSelect = identifier for a select list with multiple=true
choicesList = ArrayList of choices (type = LabelValueBeans to populate lists)
------------------------------------

Thanks for your assistance. I am stumped!

JD


New Developer<br />Happy to learn what I don't know<br />Happy to share what I do<br />
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since you have a loop within a loop, merely specifying indexed="true" with the <html:select> isn't going to work. With a more complex situation like this you either have to use the <nested> tags or build the indexed property name yourself.

If you use the Struts-el version of the tags, the following should work:



In addition to the above, you must also have indexed getters and setters for your properties. Also, if ReportListForm is in request scope, you will need to read this link carefully and follow its instructions for giving your lists "lazy initialization" behavior.


Merrill
Consultant, Sima Solutions
JD Thompson
Greenhorn

Joined: Jun 29, 2006
Posts: 21
Merrill,

Once again you have proven your stuff. I followed your advice and created a basic structure like you suggested, and voila!, the values are stored.

Thanks again for your time and clear/concise response!!

JD
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
You're very welcome. Good luck with your project.
natasa jones
Ranch Hand

Joined: Aug 20, 2006
Posts: 45
Hello!
i would like to do the exact same thing but i cannot understand the solution!i am new in struts and i know nothing about the Struts-el version of the tags.is <c:set > one of them?how can i achieve the same result with <logic:iterate>?i would like to create a drop down list.i have a List which is filled with values from the database, but now,i dont know how to create the <html:select> with the values of those objects...
could anyone help??
is there any tutorial or site that you know with relevant example code?
any help appreciated!!
Ritu Bansal
Greenhorn

Joined: Nov 07, 2007
Posts: 11
Hi, I am trying to save values of a select in a form. The select is inside 2 nested logic iterate tags similar to the solution provided below. I tried implementing it the same way but I get the following exception:

Invalid indexed property 'fileNumberBeans[indx.intValue()]' on bean class 'class com.test.OfaForm' Invalid index value 'indx.intValue()''

This is what I have in my JSP:

<logic:iterate id="fileNumberBeans" scope="request" type="com.test.FileBean" name="ofaForm" property="fileNumberBeans" indexId="indx">
<logic:notEmpty name="fileNumberBeans">
<tr>
<td class="TableBorder">
<table id="<bean:write name="fileNumberBeans" />">
<logic:iterate id="offBn" name="fileNumberBeans" type="com.test.OfaSDOBean" property="singleDefBeans" indexId="ix">
<tr>
<td id="<bean:write name="offBn" />" align="left" width="310px" class="TableBorder"> 
<bean:define id="offDetailSelectList" name="offBn" property="offDetailSelectList" type="java.util.ArrayList" />
<html:select styleClass="ListBox" property="fileNumberBeans[indx.intValue()].offBn[ix.intValue()].offDetail" name="ofaForm" size="1" >
<htmlptions collection="offDetailSelectList" property="value" labelProperty="label" />
</html:select>
</td>
</tr>
</logic:iterate>
</table>
</td>
</tr>

</logic:notEmpty>
</logic:iterate>

Any help on this will be greatly appreciated.

Ritu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Value not returned to form inside logic:iterate
 
Similar Threads
Moving ArrayList of Objects from JSP to Action
Editing and submitting multiple records
Passing data from servlet to JSP to servlet
how to populate formbean property using html:checkbox values
MultipleSelect JComboBox