0

I have a jsf form with two inputs and two validations for each one, when I fill one of these inputs (for example firstName) and then click submit, the validation fired. when I click new, it should update the whole form but it does not clear the firstNamme input, I have to mention by clicking on new the clearList function in userManagement bean is fired. if I fill firstName input and then click on new without clicking on submit, it would clear the firstName input.

        <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();
        }
    }
  • possible duplicate of [How can I populate a text field using primefaces ajax after validation errors occur?](http://stackoverflow.com/questions/6642242/how-can-i-populate-a-text-field-using-primefaces-ajax-after-validation-errors-oc) – BalusC Jun 11 '13 at 12:31

1 Answers1

0

You may use:

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

for resetting the values of the form.