2010-02-09 18 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 --> 

然後,每次阿賈克斯要求,您的彈出窗口顯示,如果阿賈克斯停止,彈出式窗口是隱藏..

希望這有助於..感謝