【问题标题】:displaytag library and selected checkbox valuesdisplaytag 库和选中的复选框值
【发布时间】:2010-10-14 17:26:45
【问题描述】:

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

当我去“编辑”用户组时,问题就来了。我想加载带有可用权限对象的整个列表的 displaytag 表,就像我在创建页面上所做的那样,但我需要能够为该用户组已经存在的权限设置复选框的“选定”值。

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

以下是用于“创建”用户组的代码:

<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”输入数据的某些属性设置复选框的“选定”属性,我将根据已为用户组选择的权限设置这些属性更新了。

我希望这对于摇滚乐来说已经足够清楚了。

提前感谢您的任何见解:)

编辑 - 我很抱歉,我相信预选复选框输入元素的方法是包含属性“checked”,我原以为它是 selected="selected" 或类似的东西。

【问题讨论】:

    标签: java html struts displaytag


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-17
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多