如何在使用Icefaces的jsf动作中使用Javascript来更新页面状态?

时间:2013-03-14 05:03:11

标签: jsf icefaces icefaces-3

如何在完成h:commondButton action时触发服务器端或客户端事件处理程序? 此服务器端进程需要一些时间才能完成。 当我单击按钮时,需要一些时间来完成工作并更新UI。当UI得到更新时,我想解雇一些东西。 我是JSF的新手。请帮帮我。

谢谢!

1 个答案:

答案 0 :(得分:2)

Icefaces有一个javascript库,可以在客户端排队事件。完成操作后,Icefaces会刷新DOM,因此您可以在操作方法结束时对事件进行排队。

这是我在Icefaces 1.8.x和2.0中使用的东西。我不太确定Icefaces 3是否添加了任何特殊组件/代码来捕获DOM更新事件。

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')"/>

您的托管Bean

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

您也可以通过在h:commandButton上使用f:ajax并在ajax调用期间重新呈现消息来轻松完成。

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