日期:2014-05-16  浏览次数:20335 次

Ext3.2.2+Struts2+Json的简单实例
这个实例不是完整的,只是个人摘取其中比较关键的代码块!写这篇文章也是对自己知识的一种管理。当然你也可以看看,说不定有你想要的。

CpAction
private static final Logger logger = Logger.getLogger(CpAction.class);
private Cp cp;
private PageList pageList;
public String listCps(){。。。}

说明:PageList类中有一个类型为List的属性result,其用于存放查询到的Cp信息。其中要记得定义pageList属性的get/set方法,不然页面将显示不了数据。

Javascript:
var cpStore = getJsonStore(ctx+'/CpManager/CpAction!listCps.action',"pageList.result",
                                    "pageList.totalCount",cpFields);//数据源
function getJsonStore(url,root,totalProperty,fields){
return new Ext.data.JsonStore({ 
url:  url,
root : root,
totalProperty : totalProperty,
fields: fields
});
}

Cp.xml
<struts>
  <package name="cpManager" extends="global" namespace="/CpManager">
    <action name="CpAction" class="ricki.iteye.com.action.CpAction">
     <result type="json"/>
    </action>
  </package>
</struts>

返回数据的JSON内容如下
{"pageList":{"result":[字段数据。。。],"totalCount":1},"success":true}

有空,欢迎到红番薯逛逛