1

当我单击命令按钮时。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"/>
4

3 回答 3

4

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

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

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

并将其包含在 ajax 更新的客户端 ID 集合中

<p:commandButton ... update="updateList updateDetails yearMessage" />

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

于 2013-09-03T11:15:54.920 回答
3

不确定updateListupdateDetails的位置,但在上面给出的示例中,您应该使用 update="@form" 代替,或者像这样添加:

update="updateList updateDetails @form" 

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

于 2013-09-03T06:36:39.657 回答
0

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

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

或者给<h:message />一个 id 和 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"/>
于 2013-09-03T06:39:42.883 回答