使用 IceFaces 进行 Ajax 样式加载

发布于 2024-08-20 22:30:50 字数 128 浏览 8 评论 0原文

我有一个页面,上面显示从 Web 服务加载的对象列表。这可能需要一段时间。 现在我想以 Ajax 方式执行此操作,首先显示页面,然后加载列表。加载列表时应显示动画。 有人能给我一个如何使用 JSF/ICEFaces 做到这一点的例子吗?谢谢。

I have a page on which I show a list of objects which are loaded from a webservice. This may take a while.
Now I'd like to do it the Ajax way and first show the page and then load the list. While the list is loading a animated should be shown.
Can anybody give me an example how to do that with JSF/ICEFaces? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

懒的傷心 2024-08-27 22:30:50

使用SessionRenderer会更好。看看我的 ICEfaces 书籍示例 (http://icecube-on-icefusion.googlecode.com/ )并搜索 ProgressDialog 标签以获取示例。或者书中第244页。

It would be better to use the SessionRenderer. Have a look at my ICEfaces book examples (http://icecube-on-icefusion.googlecode.com/) and search for the progressDialog tag for an example. Or page 244ff in the book.

有木有妳兜一样 2024-08-27 22:30:50

好吧,我自己解决了。

我是这样做的:

在托管 Bean 的构造函数中,我调用一个创建并启动新线程的方法。该线程加载对象。一旦对象出现,我的 bean 的“正在加载”标志就会设置为 false 并被

PersistentFacesState.getInstance().renderLater();   

调用。 “loading”最初设置为 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();      
        }

在视图上,我在加载标志的状态下显示或隐藏动画加载图像。

我不知道这是否是最好的,甚至是一个好的解决方案。欢迎评论。

Ok, solved it myself.

Here's how I'm doing it:

in the Managed Bean's constructor I'm calling a method which creates and starts a new thread. This thread loads the objects. As soon as the objects are there the 'loading' flag of my bean is set to false and

PersistentFacesState.getInstance().renderLater();   

is called. 'loading' is initially set to false.

That's the method for loading the objects in async mode:

 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();      
        }

On the view I'm showing or hiding an animated loading images on the state of the loading flag.

I don't know if that is the best or even a good solution. Comments are welcome.

红玫瑰 2024-08-27 22:30:50

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

您可以在页面加载时要求使用 ajax 提交一个icefaces 表单,这应该可以解决问题。

It is strongly discouraged to create new threads in a J2EE server. It's server's job to manage threads.

You can ask for the submission of an icefaces form using ajax when your page is loaded, that should do the trick.

猫卆 2024-08-27 22:30:50

我想我已经回答了这个问题,因为我对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调用你只需要显示弹出div,每次你收到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 -->

然后,每次ajax请求后,您的弹出窗口将显示,如果 ajax 停止,您的弹出窗口将隐藏..

希望有帮助..谢谢

i think i have answer for this question, because i have the same trouble about ajax style loading..

after lurking in many sites and icefaces forum, i have this code, without using thread:

first you have to download jquery, and then the code is like this:

<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">

the basic idea is simple, every ajax call you just have to show the popup div, and every you receive confirmation from icefaces js, you just have to hide the popup,

the popup panel is like this:

<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 -->

then, everytime ajax request on, your popup is show, and if ajax stop, your popup is hide..

hope this help..thanks

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文