How to use Javascript in jsf action with Icefaces to update page status ?

人走茶凉 提交于 2019-12-12 10:15:55

问题


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:


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/



来源:https://stackoverflow.com/questions/15401563/how-to-use-javascript-in-jsf-action-with-icefaces-to-update-page-status

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!