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. That Profile list has List of ProfileVO and ProfileVO has isSelected(boolean), profile id(int) and Profile name(String).
I am new to JSF and tried to use datatable and SelectBooleanCheckBox which works fine. 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. Also I am not sure how to update the bean with the options checked/unchecked by the user.
When the user clicks Submit my validations should be:
- At least one application should be selected
- If an application is selected, at least one profile should be selected
- Profile check boxes should be disabled until the application is selected
- 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:selec开发者_JAVA百科tBooleanCheckbox value="#{profileList.isSelected}" />
<h:outputText value="#{profileList.profileName}" />
</h:column>
</h:dataTable>
</h:column>
</h:dataTable>
I was able to implement by validating in the bean and was able to get the selected values from the ApplicationList
精彩评论