Make h: inputText is required only when the checkbox is selected

I have a datatable with strings containing some text input fields that are required. Each row also has a delete flag. I want to have required = "true" only when this check box is selected. How can I achieve this?

+4
source share
1 answer

Just let the input required attribute check the value of the flag.

Here is an example run:

 <h:form> <h:dataTable value="#{bean.list}" var="item"> <h:column><h:selectBooleanCheckbox binding="#{checkbox}" /></h:column> <h:column><h:inputText id="input" value="#{item.value}" required="#{checkbox.value == 'true'}" /></h:column> <h:column><h:message for="input" /></h:column> </h:dataTable> <h:commandButton value="submit" action="#{bean.submit}" /> </h:form> 
+8
source

Source: https://habr.com/ru/post/1342131/


All Articles