Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Deniz Atak
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;

if(selectedValue.equals(null))
{
((UIInput)component).setValid(false);

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
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!