This is how I had to do it - who knows why:
<p:commandButton value="Reset" icon="ui-icon-refresh" process="@this" update=":form">
<p:resetInput target=":form" clearModel="true" />
</p:commandButton>
Depending on your needs, clearModel may not be necessary. See the PrimeFaces documentation on resetInput's clearModel (defaults to false): "When enabled, reset input also sets null values to the bound values so it reset inputs values and model values."
As someone tells us here:
Just in case someone else has this same problem...
p:resetInput does NOT accept @form as a target. You must supply the
actual ID of the form/naming container that you would like to clear. I
have seen examples of code online (I think somewhere on StackOverflow)
that used @form as the target-- don't be fooled, this does not work.
This is why I used target=":form"
, because my root NamingContainer was <h:form id="form">
. There's loads of information on the NamingContainers selection stuff here.
Also, note that you can do this to have a confirm dialog first:
<p:commandButton value="Reset" icon="ui-icon-refresh" process="@this" update=":form">
<p:resetInput target=":form" clearModel="true" />
<p:confirm header="Confirm Reset" message="Are you sure you want to reset all changes?" icon="ui-icon-help" />
</p:commandButton>
<p:confirmDialog global="true" closable="true" closeOnEscape="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
</p:confirmDialog>
#{requestBean.addRequest()}
you may need to reset all values to null / blankresetValues
for <f:ajax>