Apologies for the tardiness of the reply. It was a public holiday in Oz.
Not sure exactly what you mean by what generates my form but here's my working code.
I have a checkbox class. I have a checkbox per application and a sublist of checkboxes of the roles for that application (checkboxform). Finally I have a list of applications and an associated user and their organisation. (checkboxformlist)
The naming could probably be better.
Code:
public class CheckBox {
private String itemLabel;
private boolean selected;
private String roleName;
private boolean subRole;
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public boolean isSubRole() {
return subRole;
}
public void setSubRole(boolean isSubRole) {
this.subRole = isSubRole;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
public String getItemLabel() {
return itemLabel;
}
public void setItemLabel(String description) {
this.itemLabel = description;
}
}
Code:
import java.util.List;
public class CheckBoxForm {
private List<CheckBox> subRoleList;
private CheckBox app;
public List<CheckBox> getSubRoleList() {
return subRoleList;
}
public void setSubRoleList(List<CheckBox> subRoleList) {
this.subRoleList = subRoleList;
}
public CheckBox getApp() {
return app;
}
public void setApp(CheckBox app) {
this.app = app;
}
}
Code:
public class CheckBoxFormList {
private String user;
private String organisation;
private List<CheckBoxForm> applications;
public String getOrganisation() {
return organisation;
}
public void setOrganisation(String organisation) {
this.organisation = organisation;
}
public String getUser() {
return user;
}
public void setUser(String customsUser) {
this.user = customsUser;
}
public List<CheckBoxForm> getApplications() {
return applications;
}
public void setApplications(List<CheckBoxForm> applications) {
this.applications = applications;
}
}
The controller calls a webservice that updates the roles accordingly
Code:
@RequestMapping(value = "/updateUserRoles.htm", method = RequestMethod.POST)
public String submitUpdateApplicationRoles(
@ModelAttribute("checkBoxFormList") CheckBoxFormList checkBoxFormList,
BindingResult result) throws IDMException {
String uid = checkBoxFormList.getUser();
String org = checkBoxFormList.getOrganisation();
if (org == null || uid == null) {
String message = "Organisation or Customs User cannot be null";
logger.error(message);
throw new IDMException(message);
}
CustomsUser loggedInUser = (CustomsUser) SecurityContextHolder
.getContext().getAuthentication().getPrincipal();
if (!hasAccess(org, uid, loggedInUser)) {
String message = "You don't have the authorisation to perform this action";
logger.error(message);
throw new IDMException(message);
}
UpdateTamRolesRequest updateTamRolesRequest = new UpdateTamRolesRequest();
updateTamRolesRequest.setApplicationRoles(new CheckBoxFormListJAXB(
checkBoxFormList));
updateTamRolesRequest.setOrganisation(org);
updateTamRolesRequest.setCustomsUser(uid);
proxy.callIDMWebService(IDMWebServiceCallType.EXTERNAL,
updateTamRolesRequest);
return "redirect:displayUser.htm?organisation=" + org + "&uid=" + uid;
}
The JSTL/JSP stuff
Code:
<form:form name="updateRolesForm" modelAttribute="checkBoxFormList" action="updateUserRoles.htm" method="post">
<table class="detail">
<tbody>
<form:hidden path="user" value="${customsUser.uid}"/>
<form:hidden path="organisation" value="${organisation.businessNumber}"/>
<c:if test="${status.error}">
<tr class="errors">
<td>
<form:errors/>
</td>
</tr>
</c:if>
<c:forEach var="myApp" items="${checkBoxFormList.applications}" varStatus="outer">
<ul class="roles">
<c:if test="${outer.index mod 2 == 0 }">
<tr valign="top">
</c:if>
<td>
<li class="role"><form:checkbox path="applications[${outer.index}].app.selected" /><c:out value="${myApp.app.itemLabel}" /></li>
<form:hidden path="applications[${outer.index}].app.subRole"/>
<form:hidden path="applications[${outer.index}].app.roleName"/>
<form:hidden path="applications[${outer.index}].app.itemLabel"/>
<c:forEach var="roleList" items="${checkBoxFormList.applications[outer.index].subRoleList}" varStatus="inner">
<ul class="roles">
<li class="role"><form:checkbox path="applications[${outer.index}].subRoleList[${inner.index}].selected" /><c:out value="${roleList.itemLabel}" /></li>
<form:hidden path="applications[${outer.index}].subRoleList[${inner.index}].subRole"/>
<form:hidden path="applications[${outer.index}].subRoleList[${inner.index}].roleName"/>
<form:hidden path="applications[${outer.index}].subRoleList[${inner.index}].itemLabel"/>
</ul>
</c:forEach>
</td>
<c:if test="${outer.index mod 2 == 0 && outer.index != 0}">
</tr>
</c:if>
</ul>
</c:forEach>
</tbody>
</table>
<input type="submit" value="Update User Permissions" class="submitBtn" />
</form:form>
Hope this helps. Let me know if you need any more info.
Cheers
Andy
Edit wrong jsp