struts2.1.8 +jquery easy ui,datagird的不到数据

环境struts2.1.8,用自带的那个struts2-json-plugin-2.1.8.1.jar,jso页面调试时发现可以得到action里的json对象,但就是jquery easy ui的datagird 里通过url访问都没执行action,直接跳到input 对应的页面,设了s:fielderror查看了下,说返回的rows没值,验证错误,怎么回事,jsp里没有输入啊 
action代码
Java代码   收藏代码
  1. @Controller  
  2. // 声明此类为控制层的类,且为prototype模式调用  
  3. @Scope("prototype")  
  4. @ParentPackage("json-default")  
  5. @Results( {  
  6.   
  7.         @Result(name = "success",type = "json"),  
  8.          @Result(name = "input",location = "/product/productUnitManage.jsp") })  
  9. public class ProdUnitAction extends ActionSupport {  
  10.   
  11.     private static final long serialVersionUID = -6595716080263610502L;  
  12.    
  13.     private ScmProdUnit scmProdUnit ;  
  14.     private List<ScmProdUnit> rows =new ArrayList<ScmProdUnit>();;  
  15.     private int page;  
  16.     private int total;  
  17.   
  18.     @Resource  
  19.     private ProdUnitService prodUnitService;  
  20.   
  21.     public String save() throws Exception {  
  22.         this.prodUnitService.save(this.scmProdUnit);  
  23.         return "save";  
  24.     }  
  25.   
  26.     public String update() throws Exception {  
  27.         this.prodUnitService.update(this.scmProdUnit);  
  28.         return "update";  
  29.     }  
  30.   
  31.     public String delete() throws Exception {  
  32.         this.prodUnitService.delete(scmProdUnit);  
  33.         return "delete";  
  34.     }  
  35.   
  36.     public String querybyID() throws Exception {  
  37.         scmProdUnit = prodUnitService.findById(ScmProdUnit.class, scmProdUnit  
  38.                 .getId());  
  39.         return "item";  
  40.     }  
  41.   
  42.     //@Action(value="querybyBuilde",results={@Result(type="json",name="success")})    
  43.     public String querybyBuilde() throws Exception {      
  44.         System.err.println("111111");  
  45.         StringBuffer sql = new StringBuffer();  
  46.   
  47.         sql.append("from ScmProdUnit where 1=1 ");  
  48.       
  49.         this.setRows(prodUnitService.findByConsion(sql.toString()));  
  50. //      this.setTotal(rows.size());  
  51.         System.err.println("2222222");  
  52.   
  53.         return SUCCESS;  
  54.   
  55.   
  56.     }  
  57.     @JSON(serialize = false)   
  58.     public ScmProdUnit getScmProdUnit() {  
  59.         return scmProdUnit;  
  60.     }  
  61.   
  62.     public void setScmProdUnit(ScmProdUnit scmProdUnit) {  
  63.         this.scmProdUnit = scmProdUnit;  
  64.     }  
  65.   
  66.   
  67.     public List<ScmProdUnit> getRows() {  
  68.         return rows;  
  69.     }  
  70.   
  71.     public void setRows(List<ScmProdUnit> rows) {  
  72.         this.rows = rows;  
  73.     }  
  74.   
  75.     public int getTotal() {  
  76.         return total;  
  77.     }  
  78.   
  79.     public void setTotal(int total) {  
  80.         this.total = total;  
  81.     }  
  82.   
  83.     public int getPage() {  
  84.         return page;  
  85.     }  
  86.   
  87.     public void setPage(int page) {  
  88.         this.page = page;  
  89.     }  
  90.   
  91. }  

jsp页面代码 
Java代码   收藏代码
  1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>  
  2. <%@ taglib prefix="s" uri="/struts-tags"%>  
  3.   
  4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  5. <html>  
  6.     <head>  
  7.   
  8.         <title>test</title>  
  9.         <meta http-equiv="pragma" content="no-cache">  
  10.         <meta http-equiv="cache-control" content="no-cache">  
  11.         <meta http-equiv="expires" content="0">  
  12.   
  13.         <!--     <link rel="stylesheet" type="text/css" href="../_main.css" />-->  
  14.         <link rel="stylesheet" type="text/css" href="../js/themes/default/easyui.css">  
  15.         <link rel="stylesheet" type="text/css" href="../js/themes/icon.css">  
  16.         <script type="text/javascript" src="../js/jquery-1.4.2.min.js"></script>  
  17.         <script type="text/javascript" src="../js/jquery.easyui.min.js"></script>  
  18.         <script type="text/javascript" src="../js/locale/easyui-lang-zh_CN.js"></script>      
  19.     <script>  
  20.        
  21.      $(function(){  
  22.     $('#datalist').datagrid({  
  23.         title:'单位列表',     
  24.         iconCls:'icon-ok',   
  25.         nowrap: false,  //是否只显示一行,即文本过多是否省略部分。  
  26.         striped: true,  //隔行变色  
  27.         singleSelect:true,    
  28.         url:'prod-unit!querybyBuilde.action',    
  29.         pagination:true,    
  30.         rownumbers: true,  
  31.         loadMsg:'数据加载中请稍后……',  
  32.         columns:[[     
  33.             {field:'itemid',checkbox:true},     
  34.             {field:'code',title:'单位编码',width:$(this).width()*0.4,align:'center'},     
  35.             {field:'name',title:'单位名称',width:$(this).width()*0.6,align:'center'}          
  36.      ]],          
  37.         toolbar: [{  
  38.             text: '添加',  
  39.             iconCls: 'icon-add',  
  40.             handler: function() {  
  41.             alert('添加数据')  
  42.             }  
  43.         }, '-', {  
  44.             text: '保存',  
  45.             iconCls: 'icon-save',  
  46.             handler: function() {  
  47.             alert('保存数据')  
  48.             }  
  49.         }]        
  50.         });   
  51.     });  
  52.        
  53.   
  54.     function getjsontest()  
  55.     {  
  56.         $.post("prod-unit!querybyBuilde.action",  
  57.             {             
  58.             },function(returnData,status)  
  59.             {  
  60.             if("success" == status)  
  61.                 {  
  62.                 alert("11111");  
  63.                 //var dataa= eval('('+returnData+')');   
  64.                 //alert(returnData.length);  
  65.             alert(returnData);  
  66.                                 }  
  67.             },"json"  
  68.         );  
  69.     }   
  70.            
  71.       
  72. </script>  
  73. </head>  
  74.     <body>  
  75.          <form id="myForm" method="post">  
  76.            
  77.             <fieldset>  
  78.                 <legend>  
  79.                     test  
  80.                 </legend>  
  81.                 <table width="100%" border="0" cellpadding="1" cellspacing="4"  
  82.                     class="tableStyle">  
  83.                       
  84.                     <tr align="center">  
  85.                         <td >  
  86.                             <input name="btnQuery" type="button" onClick="getjsontest()"  
  87.                                 class="button" value="查 询">                            
  88.                         </td>  
  89.                     </tr>  
  90.                 </table>  
  91.             </fieldset>  
  92.   
  93.   
  94.             <table id="datalist"></table>  
  95.   
  96. <div id="result"></div>  
  97.   
  98.   
  99. <div style="color:red">  
  100.     <s:fielderror />  
  101. </div>  
  102.   
  103.     </form>  
  104.            
  105.   
  106.     </body>  
  107. </html>  


jsp页面执行查询按钮,firebug里可以看到action返回数据 
{"code":null,"name":null,"page":0,"rows":[{"code":"xiang","id":1,"name":"箱","remark":null},{"code":"ping","id":2,"name":"瓶","remark":null},{"code":"he","id":3,"name":"盒","remark":null}],"total":0} 
但刚载入页面的时候, 
$(function(){ 
$('#datalist').datagrid({.....里这一段,url里设定的地址根本就没执行到action里面的方法, 

<div style="color:red"> 
    <s:fielderror /> 
</div> 
调试时说 Invalid field value for field  rows,action方法没执行当然为空了,它直接转到result里的input了。现在纳闷就是为什么会转,我jsp里只是显示一个datagrid,别的什么也没有啊,本来以为js有问题,瞅半天也没发现啊,什么原因啊??????? 

又试了试,发现action继承了actionSuppoet后有上面问题,去掉actionSuppoet就可以了,估计是actionSuppoet里校验出了问题,easyui的datagrid传给action的rows是int类型,但action定义了成了list,所以报类型转换错误,可这个grid插件得到返回的rows数据类型是json对象里的list,一种解决办法去掉变量rows,直接jsonObject里吧list给"rows"这个key,但我不想这样做,那应该怎么改啊?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值