C维 2011-09-14 17:15
浏览 183
已采纳

struts2+flexigrid的小例子,但数据显示不出来,不知道哪里错了

新手刚接触flexigrid,数据显示不出来,求各位解答!谢谢。

页面js代码:
JScript code

$("#showData").flexigrid({
url: 'flexi/flexi!getData.action', //链接
dataType:'json',
colModel : [
{display: '编号', name : 'id', width : 50, sortable : true, align: 'center'},
{display: '姓名', name : 'username', width : 100, sortable : true, align: 'center'},
{display: '年龄', name : 'age', width : 50, sortable : true, align: 'center', hide: false},
{display: '性别', name : 'sex', width : 50, sortable : true, align: 'center', hide: false},
{display: '邮编', name : 'email', width : 150, sortable : true, align: 'center', hide: false},
],
buttons : [
{name: '增加', bclass: 'add'},
{name: '删除', bclass: 'delete'},
{name: '修改', bclass: 'edit'},
],
searchitems : [
{display: '姓名', name : 'username', isdefault: true},
{display: '年龄', name : 'age'}
],
sortname: "id",
sortorder: "asc",
title: '用户管理',
height: 200 ,

width:700,
showTableToggleBtn : true,
usepager:true,
});

struts.xml代码:
XML code





action代码:
Java code

public class MyFlexiGridAction extends ActionSupport {

private Integer page;//当前页
private Integer totle;//共几页
private Integer rp;//每页显示条目

private List<People> rows;

public String  getData() {
    System.out.print("获取数据...");
    rows=new ArrayList<People>();
    for(int i=0;i<27;i++){
        People p=new People();
        p.setId("No."+i);
        p.setUsername("黄"+i);
        p.setAge("i");
        p.setSex("男");
        p.setEmail("hcw"+i+"@126.com");
        rows.add(p);
    }
    int totlePage=rows.size()/this.getRp();
        if(rows.size()%this.getRp()>0)
            totlePage +=1;
    this.setTotle(totlePage);

    System.out.print("共"+rows.size()+"条\n");

    return null;
}

@JSON(name="page")
public Integer getPage() {
    return page;
}
public void setPage(Integer page) {
    this.page = page;
}

 @JSON(name="totle")
public Integer getTotle() {
    return totle;
}
public void setTotle(Integer totle) {
    this.totle = totle;
}

 @JSON(name="rp")
public Integer getRp() {
    return rp;
}
public void setRp(Integer rp) {
    this.rp = rp;
}

@JSON(name="rows")
public List<People> getRows() {
    return rows;
}

public void setRows(List<People> rows) {
    this.rows = rows;
}

}

People.java里面的字段是:
private String id;
private String username;
private String age;
private String sex;
private String email;
set和get省略。

  • 写回答

2条回答 默认 最新

  • iteye_18009 2011-09-15 17:31
    关注

    [code="java"]
    public class MyFlexiGridAction implements ServletResponseAware{

    public void getData() {
    //拼好前台需要的数据格式
    .......
    //假设最终数据是Map map = .....
    //然后
    PrintWriter out = getWriter();
    out.write(JSONSerializer.toJSON(map).toString());
    }
    private PrintWriter getWriter() {
    response.setHeader("charset", "UTF-8");
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/xml;charset=UTF-8");
    try {
    return response.getWriter();
    } catch (IOException e) {
    return null;
    }
    }
    //
    }
    [/code]

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 luckysheet
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱