0

This commandButton is working:

<h:commandButton id="button_updateIt" value="#{i18n.button_update_it}"
    action="#{masterBean.update()}">         
</h:commandButton>

This ajax call is working:

<h:commandButton id="button_updateIt" value="#{i18n.button_update_it}">
    <f:ajax event="click" render=":form_2:updateMe" />            
</h:commandButton>

Why is the action attribute combined with ajax not working?

<h:commandButton id="button_updateIt"
    value="#{i18n.button_update_it}"
    action="#{masterBean.update()}">

    <f:ajax event="click" render=":form_2:updateMe" />

</h:commandButton>

I use jsf version 2.1.1 and java 1.7.0 and GlassFish Server 3.1.2 (build 23)

GF. Service
  • 108
  • 1
  • 8

1 Answers1

1

Why you're using the click event? Your form is rerendered before the action method is invoked if you're using that event.

You need to either change the event type or you need to use an listener in the f:ajax click event instead of the action in the commandButton.

<h:commandButton id="button_updateIt"
    value="#{i18n.button_update_it}"
    action="#{masterBean.update()}">

    <f:ajax render=":form_2:updateMe" />

</h:commandButton>

or

<h:commandButton id="button_updateIt"
    value="#{i18n.button_update_it}">

    <f:ajax event="click" listener="#{masterBean.update()}" 
      render=":form_2:updateMe" />

</h:commandButton>
lastresort
  • 508
  • 3
  • 15
  • I dont know how to do an java action and the refresh on data shown on the page. For example I am downloading something on button click. If there is an error, an error message should show up below the button. I wont to know how todo the refresh. – GF. Service Nov 14 '16 at 13:44
  • You need a for that. Have a look at that question: http://stackoverflow.com/questions/11029792/error-messages-on-page-with-the-hmessages-in-jsf – lastresort Nov 14 '16 at 14:23
  • I did a work around with page refresh. [link](http://stackoverflow.com/questions/16483214/how-can-i-reload-the-same-page-from-a-managedbean-in-jsf) Perhapse the event="click" was a mistake after testing multible options. looks like a good idea, I will test it next time. Thank you @lastresort – GF. Service Nov 15 '16 at 13:26