How to create a button that call a method with ajax _without_ submit?

UI Components for JSF
Post Reply
Marco Sulla
Posts: 25
Joined: 16 Jun 2021, 16:48

19 Jul 2021, 15:39

I have a form, and I want to add a button that call a backing method. At the first I used a commandButton, but when I introduced the validators, it does not work anymore, since commandButton is a submit button and a failed validation makes it not working.

How can I create a button that call a backing bean AND it's NOT a submit button?

I tried:

Code: Select all

<p:button value="add">
    <p:ajax event="click" listener="#{bean.add()}" update="@([id$=add])" />
</p:button>
An non-ajax request was fired, that was done without the parameter id in the URL. Since the page does not work without that parameter, I got an error.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

19 Jul 2021, 16:47

Switch back to your commandButton the way you had it an add either immediate="true" which skips all validators and bean binding or add process="@none" to tell it not to process any of the fields.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Marco Sulla
Posts: 25
Joined: 16 Jun 2021, 16:48

19 Jul 2021, 17:21

immediate="true" was enough! It does not work with process="@none"

Thank you a lot, you saved my day!

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

19 Jul 2021, 17:34

No prob!
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 61 guests