如何在带有Icefaces的jsf操作中使用Javascript更新页面状态? [英] How to use Javascript in jsf action with Icefaces to update page status ?

查看:116
本文介绍了如何在带有Icefaces的jsf操作中使用Javascript更新页面状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

谢谢!

推荐答案

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

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.

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

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

您的托管Bean

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

通过在h:commandButton上使用f:ajax并在ajax调用期间重新呈现消息,您也可以非常轻松地做到这一点.

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/

这篇关于如何在带有Icefaces的jsf操作中使用Javascript更新页面状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆