开发者

JSF - Bean level form validation for listbox

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 does not show the validation message. Does anyone have any opinion about this? Thanks in advance

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜