Problems binding an object to form:options
Hi!
I need to design a JSP page with two lists to add elements from one to the other and after this, send the second list in the submit action, but I can't find a way to do this.
My first approach was creating an object with two list of LabelValue (a simple object with to attributes to represent the label and tha value :p) to put in them the elements to show in the jsp page (and avoiding put them in the request and direct access them from the command object).
This object, FormData , would be like this :
Code:
public class FormData
{
private List<LabelValue> availableElements;
private List<LabelValue> currentElements;
...
}
In the controller, something like this is done:
Code:
FormData formData = new FormData();
< set lists >
model.addAttribute("formData",formData);
and in the jsp :
Code:
<form:form method="POST" modelAttribute="formData" >
<table class="addRemoveElements">
<tr>
<td>
<form:select id="availableElements" path="" size="15">
<form:options items="${availableElements}" itemLabel="label" itemValue="value"/>
</form:select>
</td>
<td>
<input type="button" value="-->" onclick="javascript:addElement(availableElements,currentElements)"/>
<br/>
<br/>
<input type="button" value="<--" onclick="javascript:removeElement(currentElements,availableElements)"/>
</td>
<td>
<form:select id="currentElements" path="currentElements" size="15">
<form:options items="currentElements" />
</form:select>
</td>
<td>
<input type="button" value="Subir" onclick="javascript:moveElementUp(currentElements)"/>
<br/>
<br/>
<input type="button" value="Bajar" onclick="javascript:moveElementDown(currentElements)"/>
</td>
<tr>
</table>
<br/>
<div class="button">
<input type="submit" value="<spring:message code="Buttons.done"/>" />
</div>
Trying to do this (and also using spring:bind surrounding the form:select), the given error is:
Code:
Caused by: javax.servlet.jsp.JspException: Type [java.lang.String] is not valid for option items
Any idea about the way of do this?
Also I want to do this in this way because I need to send the elements in the list when the form is submitted, but I don't know the way to do it (perhaps this approach is incorrect). Any suggestions?
A lot of thanks.