I have two JSF <h:selectOneMenu> components. One called category another is subcategory.
If I select category, then subcategory changes dynamically. When I click search command button, then it displays a <h:dataTable> with boolean checkboxes.
The problem is: if none of the checkboxes is selected, then I need to show the error message like “Please select any” and the same error message has to come if there is no data in the data table after pressing search button. Please suggest a solution.
That depends on how you’re grouping the checkboxes and collecting the checked items. I bet that you’re using a
Map<RowIdType, Boolean>to collect them. In that case, you just need to count the amount of checked items in the bean action method. If this equals to0, then add aFacesMessagelike follows:and display it in a
<h:messages />the usual way.You can do it the same way. In the bean action method, check how many rows are returned and if this equals to
0, then add aFacesMessage.