1
votes

How do I fire either server side or client side event handler on completion of h:commondButton action? This server side process takes sometime to complete. When I click the button, it needs some time to finish the work and update the UI. I want to fire something, when UI gets updated. I'm new to JSF. Please help me with this.

Thanks!

1
You can't do it with plain <h:commandButton> only. You will need <f:ajax> or some IceFaces commandButton component in order to achieve this. You can find lots of tutorials about JSf <f:ajax> on the net.Luiggi Mendoza
Icefaces 3 have the auto Ajax for h:commandbutton and does the DOM rerender for updated components.Avinash Singh

1 Answers

2
votes

Icefaces has a javascript library that can queue events on client side. Icefaces refreshes DOM after the completion of action so you can queue an event at the end of your action method.

This is something I have used with Icefaces 1.8.x and 2.0 . I am not very sure if Icefaces 3 has any special component/code added to capture the DOM update events.

xhtml

<script>
function toggleDisplay(id,style)
{
  document.getElementById(id).style.display = style;  
}
</script>
    <div id="msgDiv" style="display:none">Processing ..</div>
    <h:commandButton action="#{mybean.doUpdate}"
          onclick="toggleDisplay('msgDiv','visible')"/>

Your Managed Bean

    public class MyBean{
    ....
    doUpdate(ActionEvent e){
    //do stuff
     JavascriptContext.addJavascriptCall(FacesContext.getCurrentInstance(),
        "toggleDisplay('msgDiv','none');")
    }
}

You can also do it very easily by using f:ajax on h:commandButton and re-rendering your message during ajax call .

http://www.mkyong.com/jsf2/jsf-2-0-ajax-hello-world-example/