我有啊:selectOneMenu,其中填充了枚举值,工作正常.唯一的问题是,当没有选择有效值时,我不知道如何覆盖标准的JSF错误消息.错误消息总是bv:title: 'Choose' must be convertible to an enum from the enum that contains the constant 'Choose'.
虽然我已经指定了requiredmessage和validatormessage(适用于InputText),但只显示标准的JSF消息.
片段:
<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" />
Run Code Online (Sandbox Code Playgroud)
如何覆盖标准验证器消息?或者更好 - 我可以创建带有自定义错误消息的JSF messages.properties的副本(不想再次在我自己的messages.properties中定义所有错误)吗?
Bal*_*usC 11
这不是"必需"错误消息.这是一个"转换器"错误消息.当前所选项目与预期类型或列表中的任何选项都不匹配时,可能会出现这种情况.所需消息仅在当前所选项目出现时显示null.
您正在使用字符串值作为第一项.这不能转换为枚举.您需要将其设置为带有null项目值的项目标签.
<f:selectItem itemLabel="Choose" itemValue="null" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10746 次 |
| 最近记录: |