4

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.

Fuv
  • 922
  • 2
  • 12
  • 25

3 Answers3

8

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?

Community
  • 1
  • 1
Syed Anas
  • 1,459
  • 3
  • 19
  • 38
  • to me this is a better way to empty form, why? suppose there is a requirement where you want to empty some fields when closing form and some fields stay same,like when signing up for a website a dialog box asks email and password after closing and reopening you can select to empty the password field while same time not removing the email field e.t.c i would recommend this to be the better way let me know if there is even better solution thanks – Syed Anas Feb 14 '14 at 09:48
0

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>
Azfar Niaz
  • 1,516
  • 4
  • 13
  • 21
-1

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?

Community
  • 1
  • 1
Srikanth Ganji
  • 1,127
  • 1
  • 13
  • 29
  • 1
    This answer is wrong in 2 ways. The default is not that value and that wrong value doesn't "wont fire any request". – BalusC Feb 12 '14 at 09:04
  • After seeing your comments I did some research to clear my wrong perceptions and luckily I got answer from you only in stackoverflow http://stackoverflow.com/questions/5699088/what-is-the-function-of-this-exactly. My earlier answer was my understanding which is absolutely wrong. Thanks a lot for your answer. – Srikanth Ganji Feb 12 '14 at 09:22