Validation for selected row in JSF h:datatable


I am having a tough time trying to find a solution to the following design related to h:dataTable.

I have certain number of rows predisplayed. The first column is only checkboxes. The rest of the columns are disabled by default. On selecting a checkbox the elements in the corresponding rows get enabled. On submit of the for the values in the enabled row have to be validated on the server side. I am able to validate for invalid inputs but am not finding a method to use required="true" conditionally. Or any other method. Could anyone please help me on this.


Best Solution

I'm guessing you have a bean that looks something like this...

public class SomeBean {
   boolean selected = false;
   String someProperty;


If you have a controller for those beans your markup would look something like this...

<h:dataTable value="#{SomeController.someBeans}" var="someBean">
      <f:facet name="header">Select</f:facet>
      <h:selectBooleanCheckbox value="#{someBean.selected}"/>
      <f:facet name="header">Input</f:facet>
      <h:inputText value="#{someBean.someproperty}" required="#{someBean.selected}"/>
Related Question