我有一个页面,在该页面上显示从 Web 服务加载的对象列表。可能还要等一下。现在我想用 Ajax 的方式来做,首先显示页面,然后加载列表。当列表加载时,应该显示一个动画。谁能给我一个例子如何使用 JSF/ICEFaces 做到这一点?谢谢。
4 回答
好的,自己解决了。
这是我的做法:
在托管 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();
}
在视图中,我在加载标志的状态下显示或隐藏动画加载图像。
我不知道这是否是最好的,甚至是一个好的解决方案。欢迎评论。
最好使用 SessionRenderer。查看我的 ICEfaces 书籍示例 ( http://icecube-on-icefusion.googlecode.com/ ) 并搜索 progressDialog 标记以获取示例。或书中第 244 页。
强烈建议不要在 J2EE 服务器中创建新线程。管理线程是服务器的工作。
您可以在加载页面时要求使用 ajax 提交 icefaces 表单,这应该可以解决问题。
我想我有这个问题的答案,因为我在加载 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 停止,您的弹出窗口会隐藏..
希望这有帮助..谢谢