调用Validator但不显示错误消息

时间:2013-09-03 05:52:45

标签: jsf message validation

当我点击命令按钮时。调用validate方法但是没有显示错误消息..

这是我的代码..

<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"/>

3 个答案:

答案 0 :(得分:4)

您似乎期望JSF在每个ajax请求上自动更新<h:message>。这是不真实的。也许您对PrimeFaces <p:messages><p:growl>感到困惑,它们各自具有autoUpdate属性,这使您可以告诉他们在每个ajax请求时自动更新自己。

您确实需要确保ajax更新涵盖<h:message>。只需给它一个ID

<h:message id="yearMessage" ... />

并将其包含在ajax update

的客户端ID集合中
<p:commandButton ... update="updateList updateDetails yearMessage" />

另一种方法是将<h:message>替换为<p:messages autoUpdate="true">

答案 1 :(得分:3)

不确定updateListupdateDetails的位置,但在上面的示例中,您应该使用update =“@ form”代替或添加如下:

update="updateList updateDetails @form" 

这样表格将再次呈现......

答案 2 :(得分:0)

只使用其中一个: 更新整个表单以更新内容 <h:message />

<p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="@form" id="button"/>

或向<h:message />提供ID并将此ID标识为<p:commandButton/> <h:message id="msg" for="year" style="color:red"/>

<p:commandButton value="Submit" action="#{leaveController.leaveCard}" update="updateList,updateDetails,msg" id="button"/>
相关问题