This question already has answers here:
Change the default message “Validation Error: Value is required” to just “Value is required”
(2 个回答)
How to customize JSF validation error message
(3 个回答)
5年前关闭。
如何在使用主要面孔消息标签时显示自定义验证消息?
假设我有一个名为
这里描述是字段名称,所以我真正的要求是
但目前我得到这个:
我的代码:
请建议如何做到这一点。
(2 个回答)
How to customize JSF validation error message
(3 个回答)
5年前关闭。
如何在使用主要面孔消息标签时显示自定义验证消息?
假设我有一个名为
Description
的字段,我想收到这样的消息:这里描述是字段名称,所以我真正的要求是
但目前我得到这个:
我的代码:
<p:messages id="message" />
<p:inputText id="updatedescription" value="#{equipTemplateBean.equipmentSpecificationsVO.description}" requiredMessage="Please enter Description" required='true'
</p:inputText>
请建议如何做到这一点。
最佳答案
请考虑我显示自定义错误消息“此字段是必需的”的最小示例。当提交为空时:
page.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<f:view>
<h:head/>
<h:body>
<h:form>
<p:inputText id="input"
required="true"
requiredMessage="This field is required."/>
<p:message for="input"/>
<p:commandButton process="input"
update="@form"/>
</h:form>
</h:body>
</f:view>
</html>
关于jsf - Primefaces 自定义验证消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33932724/