1

I'm new java developer and I need your help. I 've seen already questions-answers with similar topic but still I am not sure how to handle it, so I thought to ask for some help.

I am using Liferay 6.2 & Spring and I have a jsp page with my form that edits a caseType. In this form I want to add a checkbox of Roles (to select the permissions). I'd like to be able to display the selected checkboxes when I edit a caseType. My main issue is that I'm not sure which variables to use.

<form:form name="wblCaseType" method="post" modelAttribute="wblCaseType" action="${saveWblCaseType}">
<form:hidden path="wblCaseTypeId" />
<br/>
    <table style="margin-left:80px">
<tbody>
        <tr>
            <td><form:label path="type"><liferay-ui:message key="type"/></form:label></td>
            <td><form:input path="type" /><form:errors path="type" cssClass="errorClass" /></td>
        </tr>
        <tr>
            <td><form:label path="createRoleIds"><liferay-ui:message key="roles"/></form:label></td>
            <td><form:checkboxes path="createRoleIds" items="${roles}" value="${wblCaseType.createRoleIds}" itemValue="name" itemLabel="roleId" /></td>
    </tr>

Thank you in advance for any help!

  • Why don't you iterate the role list and display a checkbox for each? I haven't used form:checkboxes before, is it Spring related? If not, you should use `` tags (E.g.: ``). – Peter Mar 21 '16 at 11:15
  • thank you for your response :) I am trying to implement the answer that is given here: http://stackoverflow.com/questions/35043873/spring-jsp-checkboxes-on-list-object – Eftychia Thomaidou Mar 21 '16 at 12:24

1 Answers1

1

Alright, I believe I found the solution. My problem was that I didn't have the proper getter/setter in my Dto.

So in my Controller I have the List where the Roles come from (liferay - roles)

@ModelAttribute("roles")
public List<Role> getRoles() {

    List<Role> allRoles = new ArrayList<Role>();
    try {
        allRoles = RoleLocalServiceUtil.getRoles(QueryUtil.ALL_POS,  
    ueryUtil.ALL_POS);
    } catch (SystemException e) {
        logger.error("Could Not get any Liferay Roles" + e.getMessage(), e);
    }
    return allRoles;
}

In my Dto code I have the getter and the Setter that gets/sets a concatenation of Strings.

public String[] getCreateRoleIdsArray() {
    return createRoleIds.split(",");
}

public void setCreateRoleIdsArray(String[] selectedRoles) {
    Logger.getLogger(this.getClass()).error("setCreateRoleIdsArray");
    String selRoles = new String();
    for (String role : selectedRoles) {
        selRoles = selRoles + "," + role;
    }
    setCreateRoleIds(selRoles);
}

and finally in my jsp file

<form:form name="wblCaseType" method="post" modelAttribute="wblCaseType"action="${saveWblCaseType}">
<form:hidden path="wblCaseTypeId" />
....
<tr>
    <td><form:label path="createRoleIds"><liferay-ui:message key="roles"/></form:label></td>
    <c:forEach items="${roles}" var="role">
       <td><form:checkbox path="createRoleIdsArray" id="${role.roleId}" label="${role.name}" value="${role.roleId}" /></td>
    </c:forEach>
</tr>
Niki van Stein
  • 10,564
  • 3
  • 29
  • 62