aspose file tools*
The moose likes JSF and the fly likes JSF - Bean level form validation for listbox - required = Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF - Bean level form validation for listbox - required = "true" is not working properly" Watch "JSF - Bean level form validation for listbox - required = "true" is not working properly" New topic
Author

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

Deniz Atak
Ranch Hand

Joined: Jun 29, 2011
Posts: 30
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
 
Consider Paul's rocket mass heater.
 
subject: JSF - Bean level form validation for listbox - required = "true" is not working properly