1

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

谢谢!

4

1 回答 1

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 call 期间重新呈现您的消息来非常轻松地做到这一点。

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

于 2013-03-14T05:46:20.373 回答