tags:

views:

38

answers:

1

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.

+1  A: 

if none of the checkboxes is selected, then I need to show the error message like "Please select any".

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 to 0, then add a FacesMessage like follows:

facesContext.addMessage(null, new FacesMessage("Please select any"));

and display it in a <h:messages /> the usual way.

and the same error message has to come if there is no data in the data table after pressing search button.

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 a FacesMessage.

BalusC
Thanks for ur reply
johnbritto
how I hate accepted answers with 0 upvotes ;)
Bozho
Me too, Bozho .
BalusC
btw, congratulations for the silver jsf badge :)
Bozho
@Bozho: Thanks :) Feel alone though.
BalusC
I'm on the way :)
Bozho