I'm using Spring MVC and jQuery for processing in the JSP the objects sent by the controller.
My controller is sending to the JSP multiple objects using:
modelAndView.addObject("roleForm" + rol.getRolecode(), form);
Where form is an object of the following class:
public class RoleForm
{
private String roleCode;
private LinkedHashSet<String> listEnabled;
... getters and setters ...
}
So, I'm sending objects with the key roleFormADMIN, roleFormUSER, etc. The quantity and names of these objects are not known, as they are retrieved from database.
In my JSP I'm accessing, for each rol, its correspondent RoleForm:
<c:forEach items="${rolesList}" var="role">
<div class="role" id="${role}">
<label class="adminSectionTitle">
${role}
</label>
<form:form method="post" id="roleForm${role}" modelAttribute="roleForm${role}" action="roles.html">
<fieldset>
<form:hidden path="roleCode"/>
<div class="pickList">
<fieldset class="pickItems">
<legend >Enabled</legend>
<form:select path="listFunctEnabled" id="combo1" size="5" multiple="true">
<form:options items="${listFunctEnabled}" />
</form:select>
</fieldset>
</div>
</fieldset>
<div class="formButtons">
<input type="submit" value="<fmt:message key="button.save"/>" />
<input type="button" name="reset" onclick="location.href='<c:url value="roles.html"/>'" value="<fmt:message key="button.clear"/>" />
</div>
</form:form>
</div>
</c:forEach>
The property roleCode of each RoleForm is correctly retrieved, but it can't access the property listFunctEnabled of the form (it's empty).
If I directly write the name of the form (for instance, roleFormADMIN.listFunctEnabled), then it writes every item of the list in the form:option.
If I use roleForm${role}.listFunctEnabled, then it considers this as an String and says that String has not any property called listFunctEnabled.
I need one form for each role as I need one button for each role in order to update its list of functenabled.
How could I achieve this?