1.JAVA方法
public List getResourListByAJAX(String type,Integer lateId)throws ServiceException {
List list = null;
String hsqlCondition = " from Resour a where a.type='"+type+"' and a.sortManagerModel.bh="+lateId+" order by a.photo.uploadTime desc";
list=persistenceManager.findByHQL(hsqlCondition);
return list;
}2.DWR配置文件
<dwr>
<allow>
<!-- 页面用到的类-->
<convert converter="bean" match="com.srt.eduportal.resour.entity.Photo"/>
<convert converter="bean" match="com.srt.eduportal.resour.entity.Resour"/>
<create creator="new" javascript="getResourList" >
<param name="class" value="com.srt.eduportal.resour.service.impl.ResourServiceImpl" />
</create>
</allow>
</dwr>3.页面
//页面加载时调用function init(){
getResourList.getResourListByAJAX('0',1106,gonghuitshowResour);
} //用DWR获取数组
var arr1=new Array();//公会之家图片数组
var likearr1=new Array();
var titilearr1 = new Array();
var arr2=new Array();//协会之忧图片数组
var likearr2=new Array();
var titilearr2 = new Array();
/*工会之家数据展示开始*/
function gonghuitshowResour(data){
//封装图片数组
for(i=0;i<data.length;i++){
arr1[i]='<%=url%>'+data[i].photo.photoUrl;
likearr1[i]=data[i].photo.photoWeburl;
titilearr1[i]=data[i].photo.photoSubject;
}
//调用图片预加载方法
gload();
}
var picNum=0;
//处理图片链接
function ggoUrl(){
window.open(likearr1[picNum],'_blank');
}
function gchangeImage(){
var pic=arr1;
if(picNum<pic.length-1) picNum++ ;//显示图片个数
else picNum=0;
if (document.all){
//下面注意,如果存在于FORM表单中,需要使用下面的方法,否则可直接使用name。
document.all.gonghui.filters.revealTrans.Transition=Math.floor(Math.random()*23);
document.all.gonghui.filters.revealTrans.apply();
document.all.gonghui.filters.revealTrans.play();
}
document.all.gonghui.src=pic[picNum];
// gonghui.onreadystatechange=check;
theTimer=setTimeout('gchangeImage()', 3000);
//如果不是图片,而是SWF等,可做判断,内容可在程序中做好,再放于下面。
// focustext.innerHTML='<a href='+imgLink[picNum]+' target=_blank>'+imgText[picNum]+'</a>';
//设置翻页时间
}
function LoadImageClass()
{
var me = this;
var s = []; //图片数组
this.Idx = 0; //已经被加载的图片个数
this.Num = 0; //图片总数
//下载图片
this.LoadImages = function(a)
{
s=a;
this.Num = arr1.length;
DownImg();
}
function DownImg()
{
var i=new Image();
var f = true;
i.onload= function()
{
if (f)
{
f = false
me.Idx++;
if (me.LoadIng) me.LoadIng();
if (me.Idx<me.Num) DownImg();
else if(me.CallBack) me.CallBack(s);
}
}
i.src = s[me.Idx];
}
}
//图片预加载
function gload(){
var t=new LoadImageClass();
//加载中
t.LoadIng = function() { };
//加载完毕
t.CallBack = function(arr)
{
document.all.gonghuiinit.style.display="none";
document.all.gonghuipic.style.display="";
document.all.gonghuipic.innerHTML="<a href='javascript:ggoUrl()'><img id='gonghui' border=0 src='' width='170' height='170' style='FILTER: revealTrans(duration=2,Transition=5);cursor:hand;margin-top:10px;margin-left:10px;' />";
gchangeImage();
}
//调用加载程序
t.LoadImages(arr1);
}4.DIV
<div id="gonghuiinit" align="center">
<table width="170" height="170"><tr><td></td></tr><tr><td>正在加载中.....</td></tr></table>
</div>
<div id="gonghuipic" align="center" style="display:none">
</div>