Validation for selected row in JSF h:datatable

datatablejsfvalidation

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.

Thanks
Barun

Best Answer

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">
   <h:column> 
      <f:facet name="header">Select</f:facet>
      <h:selectBooleanCheckbox value="#{someBean.selected}"/>
   </h:column>
   <h:column> 
      <f:facet name="header">Input</f:facet>
      <h:inputText value="#{someBean.someproperty}" required="#{someBean.selected}"/>
   </h:column>
</h:dataTable>
Related Topic