tags:

views:

591

answers:

1

I have a h:selectOneMenu thats filled with enum values, which works fine. The only problem is that i don't know how to overwrite the standard JSF error message, when no valid value is selected. The error message is always bv:title: 'Choose' must be convertible to an enum from the enum that contains the constant 'Choose'. Although i have specified requiredmessage and validatormessage (which works on InputText), only the standard JSF message is shown.

The snippet:

<h:selectOneMenu id="title" value="#{personBean.person.title}" required="true"
                  requiredMessage="ERROR"
                  validatorMessage="ERROR">
  <f:selectItem itemValue="Choose" />
  <f:selectItems value="#{personBean.titleOptions}" />
  <f:ajax event="blur" render="titleError" />
  <f:validateRequired/> 
</h:selectOneMenu> 
<h:message for="title" errorClass="invalid" id="titleError" />

How can i overwrite the standard validator message? Or better - can i create a copy of the JSF messages.properties with customized error messages (don't want to define all errors in my own messages.properties again)?

+3  A: 

This is not a "required" error message. This is a "converter" error message. This may appear when the currently selected item does not match the expected type nor any of the options in the list. The required message will only appear when the currently selected item is null.

You're using a string value as first item. This is not convertible to an enum. You need to set it as item label with a null item value.

<f:selectItem itemLabel="Choose" itemValue="null" />
BalusC
Great, works perfect - thanks!!!I replaced the selectItem with yours and defined converterMessage="Please choose a value"' in selectOneMenu.
ifischer
You're welcome.
BalusC