سؤال

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!

هل كانت مفيدة؟

المحلول

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/

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top