简体   繁体   English

JSF数据表和SelectBooleanCheckBox

[英]JSF Datatable and SelectBooleanCheckBox

I have a scenario where I have to give an option to the user to select Applications and its related Profiles. 我有一种情况,我必须给用户一个选项,以选择“应用程序”及其相关的“个人档案”。 The user should select at least one Application and One Profile and he can also select more than one. 用户应至少选择一个应用程序和一个配置文件,并且他也可以选择多个。 Each Application has its own Profiles and there can be multiple applications. 每个应用程序都有自己的配置文件,并且可以有多个应用程序。 My UserBean has a List of ApplicationVO and that ApplicationVO has isSelected (boolean), application id (int), application name(String) and Profile List. 我的UserBean有一个ApplicationVO列表,而ApplicationVO有isSelected(布尔值),应用程序ID(整数),应用程序名称(字符串)和配置文件列表。 That Profile list has List of ProfileVO and ProfileVO has isSelected(boolean), profile id(int) and Profile name(String). 该配置文件列表具有ProfileVO列表,而ProfileVO具有isSelected(boolean),配置文件ID(int)和配置文件名称(String)。

I am new to JSF and tried to use datatable and SelectBooleanCheckBox which works fine. 我是JSF的新手,并尝试使用datatable和SelectBooleanCheckBox正常工作。 But at this point I am not sure how to validate and display the error message in the same JSP with the remaining user entered data intact. 但是在这一点上,我不确定如何在剩余用户输入的数据完整的情况下,在同一JSP中验证和显示错误消息。 Also I am not sure how to update the bean with the options checked/unchecked by the user. 另外,我不确定如何使用用户选中/未选中的选项来更新Bean。

When the user clicks Submit my validations should be: 当用户单击提交时,我的验证应为:

  1. At least one application should be selected 至少应选择一个应用程序
  2. If an application is selected, at least one profile should be selected 如果选择了一个应用程序,则至少应选择一个配置文件
  3. Profile check boxes should be disabled until the application is selected 在选择应用程序之前,应禁用配置文件复选框
  4. When the user unchecks the application check box, profiles check box should be disabled. 当用户取消选中应用程序复选框时,应该禁用配置文件复选框。

I have the following code. 我有以下代码。 Please help me and can also suggest me if there are any other best way to accomplish the same. 请帮助我,也可以建议我是否还有其他最佳方法来实现这一目标。

<h:dataTable value="#{UserBean.applicationList}" var="appList">
    <h:column>
        <f:facet name="header">
            <h:outputText value="Applications" />
        </f:facet>
        <h:selectBooleanCheckbox value="#{appList.isSelected}" label="#{appList.applicationName}"/>
        <h:outputText value="#{appList.applicationName}" />
    </h:column>
    <h:column>
        <f:facet name="header" >
            <h:outputText value="Profiles" />
        </f:facet>
        <h:dataTable value="#{appList.profileList}" var="profileList">
            <h:column>
                <h:selectBooleanCheckbox value="#{profileList.isSelected}" />
                <h:outputText value="#{profileList.profileName}" />
            </h:column>
        </h:dataTable>
    </h:column>
</h:dataTable>

我能够通过在Bean中进行验证来实现,并且能够从ApplicationList中获取选定的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM