验证失败后,表单的某些输入不会刷新

时间:2013-06-11 12:29:40

标签: jsf primefaces

我有一个jsf表单,每个表单有两个输入和两个验证,当我填写其中一个输入(例如firstName)然后单击“提交”时,验证被触发。当我点击new时,它应该更新整个表单,但它不会清除firstNamme输入,我必须通过点击new来提及userManagement bean中的clearList函数被触发。 如果我填写firstName输入然后点击new而不点击提交,它将清除firstName输入。

        <p:layout id="manageServiceLayout">
            <p:panel header="#{i18n['add_new_user']}"
                style="text-align:right; margin:10px">
                <p:messages />
                <h:panelGrid columns="3" class="mar">
                    <h:outputText value="* #{i18n['user_firstName']}: " />
                    <p:inputText id="firstName" binding="#{firstName}"
                        value="#{userManagement.user.firstName}"       required="true"
                        requiredMessage="#         {i18n['user_firstName_required']}" />
                    <h:outputText value="* #{i18n['user_lastName']}: " />
                    <p:inputText id="lastName" value="#{userManagement.user.lastName}"
                        required="true"
                        requiredMessage="#{i18n['user_lastName_required']}" />
                </h:panelGrid>
            </p:panel>
            <p:commandButton value="#{i18n['submit']}" update=":addUserform" id="submit">
                <f:actionListener
                    binding="#{userManagement.updateActionEditOrAddUser}" />
                <f:actionListener binding="#{tableUserBean.updateAction}" />
            </p:commandButton>
            <p:commandButton value="#{i18n['delete']}"
                rendered="#{userManagement.update}"
                actionListener="#{userManagement.deleteUser}"
                action="#{tableUserBean.updateTableUserBean}" update=":addUserform">
            </p:commandButton>

            <p:commandButton value="#{i18n['new']}" process="@this" id="new"
                action="#{userManagement.clearList}"
                partialSubmit="true"
                update=":addUserform">
            </p:commandButton>
        </p:layout>

</h:form>


//////function in userManagement bean
public void clearList() {
        try {
            User user = new User();
        } catch (SystemException e) {
            e.printStackTrace();
        }
    }

1 个答案:

答案 0 :(得分:0)

您可以使用:

<p:commandButton value="#{i18n['new']}" process="@this" id="new" action="#userManagement.clearList}" partialSubmit="true" update=":addUserform">
    <p:resetInput target=":addUserform" />
</p:commandButton>

用于重置表单的值。