views:

51

answers:

1

I am using the displaytag library to display a list of "permission" objects. The permission object contains an id, name, value, and associated application ID. When creating a "user group" one sets the name of the user group, the description, and selects the permissions to add to it by scrolling through the list in the displaytag table and checking the permissions desired with the checkbox.

The problem comes when I go to "edit" the user group. I want to load the displaytag table with the entire list of available permission objects, as I do on the create page, but I need to be able to set the "selected" value of the checkbox for the permissions that already exist for that usergroup.

My issue is how do I set the selected attribute on the checkbox. Is there some kind of "logic" functionality to the displaytag library where I can optionally set the selected attribute of the checkbox tag?

Below is the code as it is for the 'creation' of the UserGroup:

<display:table class="dataTable" defaultsort="1" name="userGroupForm.permissionList" id="tbldata" requestURI="/createUserGroup.do" pagesize="100">
    <display:setProperty name="paging.banner.onepage" value=""></display:setProperty>
    <display:column class="alignCenter" title=""><input type="checkbox" name="permIDs" value='<%=((Permission)pageContext.getAttribute("tbldata")).getPermissionCodeID() %>' /></display:column>
    <display:column class="alignLeft" property="permName" titleKey="label.name" sortable="true" />
    <display:column class="alignLeft" property="permValue" titleKey="label.value" sortable="true" />
    <display:column class="alignLeft" property="applicationName" titleKey="label.appname" sortable="true" />
</display:table>

So the idea would be, for the update page, to set the 'selected' attribute of the checkbox based on some property of the "permissionList" input data that I will set according to what permissions were already chosen for the UserGroup being updated.

I hope that was clear enough for rock and roll.

Thanks in advance for any insights :)

EDIT - I apologize, I believe the way to preselect the checkbox input element is to include the attribute "checked", I had thought it was selected="selected" or something like that.

A: 

This is how I solved it - I put an attribute in the ListObject to set if its been selected or not and pre set those values in the action before displaying the permission list:

            <display:table class="dataTable" defaultsort="1" name="userGroupForm.permissionList" id="tbldata" requestURI="/gotoUpdateUserGroup.do" pagesize="100">
                <display:setProperty name="paging.banner.onepage" value=""></display:setProperty>
                <% if (isAdmin == true) { %>
                <display:column class="alignCenter" title="">
                <input type="checkbox" name="permIDs" 
                       value='<%=((Permission)pageContext.getAttribute("tbldata")).getPermissionCodeID() %>' 

                       <%                            
                       String checked = "";
                       boolean selected = ((Permission)pageContext.getAttribute("tbldata")).getIsSelected();

                       if (selected == true) { checked = "checked"; } else { checked = ""; }
                       %>

                       <%= checked %> />
                </display:column>
                <% } %>
                <display:column class="alignLeft" property="permName" titleKey="label.name" sortable="true" />
                <display:column class="alignLeft" property="permValue" titleKey="label.value" sortable="true" />
                <display:column class="alignLeft" property="applicationName" titleKey="label.appname" sortable="true" />
            </display:table>
Matt1776