我在jsf中有一个表单,为此我创建了一个特殊的验证器类,该类检查该字段是否为:null,空,有效,数字等。如果输入无效,则该类将引发异常并显示一条消息。问题是,当我在输入字段中输入字母时(输入应为int!),我得到的是默认验证消息,而不是自定义消息。如何禁用默认验证消息?
这是带有默认验证消息的图像:
JSF代码:
<h:form>
<h:inputText value="#{deleteEmployeeBean.employeeId}"
id="employeeId" name="employeeId">
<f:validator validatorId="idValidator" for="employeeId"></f:validator>
</h:inputText>
<h:message for="employeeId" style="color: red;"></h:message>
<h:commandButton action="#{deleteEmployeeBean.loadEmployee}"
value="#{content.searchButton}"></h:commandButton>
</h:form>
答案 0 :(得分:0)
您可以将validatorMessage
用于f:validator
<h:inputText value="#{deleteEmployeeBean.employeeId}"
id="employeeId" name="employeeId" validatorMessage="your message">
<f:validator validatorId="idValidator" for="employeeId"></f:validator>
</h:inputText>
或者您可以使用它让用户仅插入数字
<h:inputText value="#{deleteEmployeeBean.employeeId}"
id="employeeId" name="employeeId" validatorMessage="your message"
onkeypress="if(event.which < 48 || event.which > 57 ) if(event.which != 8) return false;">
<f:validator validatorId="idValidator" for="employeeId"></f:validator>
</h:inputText>