6

I need to prevent it because I'm losing the params from the page when the button is clicked.

This is my code:

<h:commandLink styleClass="ui-btn ui-btn-c ui-icon-arrow-r ui-btn-icon-right" value="Continuar" action="#{metaWEB.btnProximo()}" />

I found some results here, like that How make commandButton not fully refresh page? How to use f:ajax?

But my action use messages from the page, so it need reload the form, but the page not.

I found this thread https://stackoverflow.com/questions/18868130/preventing-jsf-commandbutton-from-reloading-the-page/18868374#18868374

I think could be my solution, but I don't understand what he did :(

Thanks Advanced

Community
  • 1
  • 1
Cechinel
  • 657
  • 1
  • 8
  • 25
  • Do you have any idea about AJAX ? – Hatem Alimam Jan 16 '14 at 13:40
  • In addition to @BalusC' answer: your `listener` can be any method, just make sure you call it like that: `listener="#{metaWEB.btnProximo()}"` - the `()` part is important here. – mabi Jan 16 '14 at 13:55

2 Answers2

11

Just make it an ajax (asynchronous) button instead of a regular (synchronous) button. It's a matter of nesting a <f:ajax> inside the existing tag.

<h:commandLink ...>
    <f:ajax execute="@form" render="@form" />
</h:commandLink>

The execute="@form" tells JSF to process the entire form (all input components enclosed in the form the command component is sitting in). The render="@form" tells JSF to update the entire form as ajax response (so if you display messages inside the very same form, they would be updated as well).

Don't forget to make sure that you return null or void from the button's action method, otherwise the view may still change as consequence of a non-null/void navigation outcome.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
3

Just remember to change the render="@none" to not reload the page...

<f:ajax execute="@form" render="@none" />
Sergeenho
  • 189
  • 1
  • 7