调用验证程序,但不显示错误消息 [英] Validator is called but error message is not displayed
问题描述
当我单击命令按钮时.调用validate方法,但未显示错误消息.
when i click on the command button. validate method is getting called but the error message is not getting displayed..
这是我的代码.
<h:form id="form">
<h:body>
<p:panel style="width:500px">
<h:outputLabel for="year" value="Select Year: *" style="font-weight:bold" />
<p:selectOneMenu id="year" value="#{leaveBean.year}">
<f:selectItem itemLabel="Select One" itemValue="null" />
<f:selectItems value="#{leaveBean.yearDTO}" var="currentUser" itemValue="#{currentUser.name}" itemLabel="#{currentUser.name}" />
<f:validator validatorId="LeaveCardValidator" />
</p:selectOneMenu>
</p:panel>
<p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="updateList,updateDetails" id="button"/>
<h:message for="year" style="color:red"/>
推荐答案
您似乎希望JSF在每个ajax请求上自动更新<h:message>
.这是不正确的.也许您对PrimeFaces <p:messages>
或<p:growl>
感到困惑,它们每个都有一个autoUpdate
属性,使您可以告诉他们在每个ajax请求中自动更新.
You seem to expect that JSF auto-updates the <h:message>
on every ajax request. This is untrue. Perhaps you're confusing with PrimeFaces <p:messages>
or <p:growl>
which have each an autoUpdate
attribute which enables you to tell them to auto-update themselves on every ajax request.
您确实需要确保ajax更新覆盖了<h:message>
.只需给它一个ID
You really need to make sure that the <h:message>
is covered by the ajax update. Just give it an ID
<h:message id="yearMessage" ... />
并将其包含在ajax更新的客户端ID集合中
and include it in the client ID collection of the ajax update
<p:commandButton ... update="updateList updateDetails yearMessage" />
另一种选择是将<h:message>
替换为<p:messages autoUpdate="true">
.
An alternative would be to replace <h:message>
by <p:messages autoUpdate="true">
.
这篇关于调用验证程序,但不显示错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!