displaytag库和选中的复选框值

时间:2010-10-14 17:26:46

标签: java html struts displaytag

我正在使用displaytag库来显示“权限”对象列表。权限对象包含id,名称,值和关联的应用程序ID。创建“用户组”时,可以设置用户组的名称和描述,并通过滚动显示标签表中的列表并使用复选框检查所需权限来选择要添加的权限。

当我去“编辑”用户组时出现问题。我想像在创建页面上一样加载带有可用权限对象的完整列表的displaytag表,但我需要能够为该用户组已存在的权限设置复选框的“selected”值。

我的问题是如何在复选框上设置所选属性。 displaytag库是否有某种“逻辑”功能,我可以选择设置复选框标签的选定属性?

以下是“创建”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>

因此,对于更新页面,想法是根据“permissionList”输入数据的某些属性设置复选框的“selected”属性,我将根据已为UserGroup选择的权限设置该属性更新。

我希望摇滚乐足够清楚。

提前感谢任何见解:)

编辑 - 我道歉,我相信预选复选框输入元素的方法是包含属性“已检查”,我原以为它被选中=“已选中”或类似的东西。

1 个答案:

答案 0 :(得分:1)

这就是我解决它的方法 - 我在ListObject中放置一个属性来设置它是否被选中,并在显示权限列表之前在操作中预先设置这些值:

            <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>