1

The documentation on the Primefaces showcase page gives a number of examples for ajax and non-ajax reset buttons. One is called "reset fail" and it can be found here. It simply involves calling an actionListener which sets all relevant backing bean fields to null.

I tried "reset fail" and it seems to do the job. So why is it a "fail" example and why do the docs say it "won't work"?

Thanks!

nettie
  • 628
  • 1
  • 11
  • 23

2 Answers2

1

OK try this...

  1. On that Showcase demo page enter "a" in the first field and "bbb" in the second field and press "Submit". You will get a validation error.

  2. Now press "Reset Fail". See how the first field is still highlighted RED as validation has failed?

  3. Now press "Reset Tag" and you will see the RED highlighted field go away.

So the difference is the Reset Fail doesn't reset the validation failures and Reset Tag does.

Melloware
  • 10,435
  • 2
  • 32
  • 62
  • Yes, you are right, thanks. I wish there were a backing bean solution to reset fields. "p:resetInput" does not work for me. – nettie Jul 12 '18 at 15:36
1

In the end, a combination of actionListener= and resetValues="true" worked for me, i.e:

<p:commandButton value="Reset" actionListener="#{otb.resetFail}" process="@this" update="@form" resetValues="true" style="margin-left:20px;"/>

Without the actionListener my fields don't clear properly. But the resetValues attribute is needed to get around the validation issue. I got this idea from the StanL answer in this post.

One more thing - in contrast to the example in the PF demo, my bean's "resetFail" method just nulls out the fields. It does not call PrimeFaces.current().resetInputs("form:panel"); (I don't have that library). Still, it works fine.

nettie
  • 628
  • 1
  • 11
  • 23