How to use Javascript in jsf action with Icefaces

2019-06-04 07:09发布

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条回答
SAY GOODBYE
2楼-- · 2019-06-04 07:46

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/

查看更多
登录 后发表回答