1

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)

1 Answer 1

2

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>
Sign up to request clarification or add additional context in comments.

3 Comments

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.
You need a <h:message> for that. Have a look at that question: stackoverflow.com/questions/11029792/…
I did a work around with page refresh. link Perhapse the event="click" was a mistake after testing multible options. <h:message> looks like a good idea, I will test it next time. Thank you @lastresort

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.