2010-02-09 30 views
1

我有一个页面,其中显示了从web服务加载的对象列表。可能还要等一下。 现在我想用Ajax的方式做,并首先显示页面,然后加载列表。应该显示列表正在加载动画时。 任何人都可以给我一个例子如何用JSF/ICEFaces做到这一点?谢谢。使用IceFaces加载Ajax样式

回答

0

使用SessionRenderer会更好。查看我的ICEfaces书籍示例(http://icecube-on-icefusion.googlecode.com/),并搜索progressDialog标签作为示例。或书中的第244ff页。

+0

PersistentFacesState有什么问题,什么使SessionRenderer更好?我的方法可以解决哪些问题?它似乎工作... – hugri 2010-02-13 20:18:57

0

好的,自己解决吧。

这里是我如何做它:

在Managed Bean的构造

我打电话从而创建并启动一个新的线程的方法。该线程加载对象。只要对象在那里,我的bean的'加载'标志被设置为false,并且

PersistentFacesState.getInstance().renderLater(); 

被调用。 '加载'最初设置为false。

这对装载在异步模式中的对象的方法:

private void asyncLoading() { 
      final MyBackingBean bean = this; 
      final String userName = CallerContextUtil.getCurrentUserCompany(); 
      new Thread() { 
       @Override 
       public void run() { 
        bean.setLoading(true); 
        PersistentFacesState.getInstance().renderLater();  
        load(userName);     
        bean.setLoading(false);    
        PersistentFacesState.getInstance().renderLater();     
       } 
      }.start();  
     } 

在我展示或在装载标志的状态隐藏动画加载图像的图。

我不知道这是最好的还是最好的解决方案。欢迎评论。

0

强烈建议在J2EE服务器中创建新线程。管理线程是服务器的工作。

当你的页面被加载时,你可以要求提交一个使用ajax的icefaces表单,这应该可以做到。

+0

我怎样才能问“使用ajax提交icefaces”?谢谢! – hugri 2010-02-13 20:20:27

+0

这个想法可以是在页面加载时在页面上放置隐藏窗体。每个JS框架都有这样的功能(相当于body onload =“form”。提交();“) 从这一点,就好像你要求提交表单提交一个Ajax刷新 这是非常基本的,可能不适合更复杂的情况,但它具有简单性的优点。如果你想要更复杂的事情,更好地使用rainwebs的方法,它似乎更符合ICEFaces的做法。 – Awano 2010-02-15 09:08:32

0

我想我有答案这个问题,因为我对AJAX式装载同样的烦恼..

潜伏在许多网站和论坛ICEfaces的,我有这样的代码,而无需使用螺纹:

首先你要下载的jQuery,然后将代码是这样的:

<script type="text/javascript" src="js/jquery-1.6.min.js"/> 
     <script type="text/javascript"> 
      var j = jQuery.noConflict(); 

      j(document).ready(function(){ 
       j(".wrapper-popup-loading").hide(); 
      }); 

      function icesubmitlocal() { 
       var windowWidth = document.documentElement.clientWidth; 
       var windowHeight = document.documentElement.clientHeight; 
       var popupHeight = j(".wrapper-popup-loading").height(); 
       var popupWidth = j(".wrapper-popup-loading").width(); 

       j(".wrapper-popup-loading").css({ 
        "position": "absolute", 
        "top": windowHeight/2-popupHeight/2, 
        "left": windowWidth/2-popupWidth/2 
       }).show(); 
       j(".wrapper-popup-white").show(); 
      } 


      function icereceivelocal() { 
       j(".wrapper-popup-loading").hide(); 
       j(".wrapper-popup-white").hide(); 
      } 

      function init() { 
       Ice.onSendReceive('document:body',icesubmitlocal,icereceivelocal); 
      } 
     </script> 

     <body onload="init()" id="outputBody1" style="-rave-layout: grid"> 

的基本想法很简单,每一个AJAX调用,你只需要显示弹出股利,每一次你从ICEfaces的JS收到确认,你只需要隐藏流行音乐起来,

在弹出的面板是这样的:

<div class="wrapper-popup-loading"><!-- start wrapper --> 
        <div class="wrapper-popup-white"><!-- start wrapper --> 
         <center> 
          <img src="images/aed-popup.png" alt="" style="margin-top: 5px;"/> 
          <br /> 
          <img src="images/aed-garuda.gif" alt="" style="margin-top: 5px;"/> 
         </center> 
        </div> 
       </div><!-- end footer --> 

然后,每次阿贾克斯要求,您的弹出窗口显示,如果阿贾克斯停止,弹出式窗口是隐藏..

希望这有助于..感谢