java Primefaces - 不显示必填字段的消息,只高亮边框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14157892/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Primefaces - Do not display message for required fields, just hightlight border
提问by CountD
I have a Primefaces 3-field form and a <p:messages>
tag to show some server-side validation messages. But I don't want to display the client-side messages related to the required="true"
option, just highlight the input field with red.
我有一个 Primefaces 3 字段表单和一个<p:messages>
标签来显示一些服务器端验证消息。但我不想显示与该required="true"
选项相关的客户端消息,只需用红色突出显示输入字段。
Is there a way to do it with Primefaces?
有没有办法用 Primefaces 做到这一点?
回答by partlov
You can set <p:messages globalOnly="true"/>
, this will just show global messages, which are not attached to any particular field. Also you can user Primefaces' <p:outputLabel/>
for label of input elements, it will add error css to input elements.
您可以设置<p:messages globalOnly="true"/>
,这将只显示全局消息,不附加到任何特定字段。您也可以使用 Primefaces'<p:outputLabel/>
作为输入元素的标签,它将向输入元素添加错误 css。
You should also update form when you do submit. For example if you do that with command button add update="form_id"
您还应该在提交时更新表单。例如,如果您使用命令按钮添加update="form_id"
回答by Igor Vukovi?
I did it like this --> rendered="#{not facesContext.validationFailed}"
我是这样做的 -->渲染 =“#{not facesContext.validationFailed}”
<p:messages
rendered="#{not facesContext.validationFailed}"
id="msg"
showDetail="true"
autoUpdate="false"
closable="true" />