1

I need use the button to call a method of a Managed Bean but it doen't have any ActionListener. I have something like this:

<b:button value="Tes1"  look="warning"size="lg"/>

I can't use the commandButton. Is there any way? Thanks!

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • Why can't you use a commandButton? You need the 'get'? Only solution is then to call some javascript that calls a remote action that does a 'post-redirect-get', but then you effectively created a commandButton that should do the same 'PRG'.... So – Kukeltje May 25 '17 at 11:27
  • I need it to be out of a form, commandButton needs to be inside a form. – Enrique de Miguel May 25 '17 at 11:31
  • Why do you need it outside a form? – Kukeltje May 25 '17 at 11:32
  • The button opens a `b:modal`. If I use a commanButton it performs a submmit and it doesn't show the modal window. – Enrique de Miguel May 25 '17 at 11:41
  • Then fix that problem!... Must be simple, since I use a commandButton all the time with opening modal dialogs/windows without any problems. Only not with BoostFaces but PrimeFaces, but they behave the same... – Kukeltje May 25 '17 at 11:43
  • You mean not let it submmit? If I do that I woudn't perform an action in my managed bean. – Enrique de Miguel May 25 '17 at 11:50
  • 1
    Uuuhhh yes and no... Not submitting and fields does not mean you cannot call an action. https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes – Kukeltje May 25 '17 at 12:29
  • That's it! That helped me! I give you a point – Enrique de Miguel May 25 '17 at 14:35

1 Answers1

1

In the question and the attempted solution, it was indeed approaching it from the wrong way. A b:commandButton can be used in the following way:

<b:commandButton value="Trigger (JSF passthrough)2" actionListener="#{managedBeanName.performCall}" immediate="true" update="@(#id_element)"/>

The key of this solution are immediate=true to scape validations and update="@(#id_element)" to update only a part of the screen. You could also use update="@none" to don't update the screen.

It needs to be inside a form.

Another option is to use process="@this" instead of immediate=true. In this way, it doesn't perform any validation since it does not submit any inputs from the form.

<b:commandButton value="Trigger (JSF passthrough)2" actionListener="#{managedBeanName.performCall}" process="@this" update="@(#id_element)"/>

Since the introduction of 'ajax' in JSF, this latter solution is more commonly used.

See also:

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • That skips validation but does sub,it the values.So you **do** want to submit? otherwise `process="this"` would be a better option. No validation and no submitting the values. Using this instead of the `immediate="true"` is better in modern ajax based solutions – Kukeltje May 25 '17 at 16:13
  • See https://stackoverflow.com/questions/10502326/should-immediate-true-never-be-used-when-dealing-with-an-ajaxified-jsf-2-0-com for the `immediate="true"` in combination with ajax `b:commandButton` is ajaxified by default – Kukeltje May 26 '17 at 07:18
  • It doesn't mater if it submits the form but I could add that to my answer so it's a more complete solution... – Enrique de Miguel May 26 '17 at 07:35
  • Improved answer – Enrique de Miguel May 26 '17 at 09:08
  • But what you describe now as the 'other' option, is, since 'ajax' exists, the better option. It is not clear from this answer why you choose the less good one. – Kukeltje May 26 '17 at 09:11