Fuv
Fuv

Reputation: 922

Primefaces process attribute in reseting form inputs

I have a form inside a modal dialog and after closing (hiding in fact) one I wanted to reset all inputs that user might have changed. I though about something like as follow:

<p:dialog widgetVar="myDialog">
    <h:form id="formId">
        <!-- ... -->
        <p:commandButton value="Cancel" onclick="myDialog.hide();"
            update="formId">
            <p:resetInput target="formId" />
        </p:commandButton>
    </h:form>
</p:dialog>

But the result was not that I expected. After a while of searching I found a solution that was to add process="@this" attribute to the <p:commandButton>. And my question is why it is necessary? What is really happening in backgroud that this process is desired. I don't really get the idea of process attribute at all.

Upvotes: 4

Views: 2786

Answers (3)

Syed Anas
Syed Anas

Reputation: 1476

I have done some work with dialog boxes and the way I did to make the form null is, when clicking the button to open dialog box, I ran a method in backing bean which cleared my pojo so my form had empty values.

In your case it could be something like this:

<h:form id="form-button">
    <p:commandButton id="AddButton" value="open dialog box"
        update=":form" action="#{myBean.myMethodToSetPojoNull}" immediate="true"
        oncomplete="PF('myDialog').show()" />
</h:form>

When clicking this button, the called method will set to null all the fields and your dialog box will be empty. Getting back to your question of why process=@this is neccessary much better explained answer is here

What is the function of @this exactly?

Upvotes: 8

Azfar Niaz
Azfar Niaz

Reputation: 1546

You can also reset input after submitting through this method:

<p:commandButton value="Reset Non-Ajax"
    actionListener="#{pprBean.reset}" immediate="true" ajax="false">
    <p:resetInput target="panel" />
</p:commandButton>

Upvotes: 0

Srikanth Ganji
Srikanth Ganji

Reputation: 1157

If you don't add process="@this" then by default attribute value will be set to process="@form" which means all the elements in the form are processed. In command buttons process="@this" is mandatory to execute the corresponding actions associated with that button.

You can directly refer the answer from Balusc in this link
What is the function of @this exactly?

Upvotes: -1

Related Questions