• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF - Bean level form validation for listbox - required = "true" is not working properly  RSS feed

Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
0 down vote favorite

I have a form designed in JSF. I need to check if a listbox item is selected. I am doing bean-level validation. My code is:

<webuijsf:listbox style="margin-left:10px;" binding="#user$webreports$frequentvisitorscategories.listBox}"
id="listbox" items="#frequentvisitorscategories.listboxDefaultOptions.options}"
selected="#{user$webreports$frequentvisitorscategories.selectedItemCategory}" rows="10"
styleClass="listbox" multiple="true" width="190" required="true" validatorExpression="#{frequentvisitorscategories.category_validate}" />
public void categories_validate(FacesContext context, UIComponent component, Object value)
{ String selectedValue = (String) value;


FacesMessage message = new FacesMessage("Please select a category");

context.addMessage(component.getClientId(context), message);

When I don't select something it doesn't submit the form but also it does not show the validation message. Does anyone have any opinion about this? Thanks in advance
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!