极度郁闷后台获取不到start和limit,前台配置了store.load...

demo_3312 2008-05-30
  通过节点的 href:'documentManagement/locator.jsp'  把l locator.jsp显示在TablePanle中,也就是点左边Tree,右边显示网页

locaotr.jsp的代码:
<%@ page language="java" pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
    <title>locator.jsp</title>
    <link rel="stylesheet" type="text/css" href="../extjs/resources/css/ext-all.css" /><!-- 样式文件 -->
    <script type="text/javascript" src="../extjs/adapter/ext/ext-base.js"></script><!-- 框架基础库 -->
    <script type="text/javascript" src="../extjs/ext-all.js"></script><!--EXT核心库 -->
    <script type="text/javascript" src="../extjs/ext-lang-zh_CN.js"></script>
    <script type="text/javascript">
                    Ext.onReady(function(){
                        Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8';//解决乱码       
                        Ext.QuickTips.init();//信息提示,包括button的和验证的

                    var store = new Ext.data.Store({ //通过它我们可以把任何格式的数据转化成grid可以使用的形式
                      proxy: new Ext.data.HttpProxy({
                                 url:'locator.do?method=initLocator' ,
                                 scripts:true
                              }),  
                      reader: new Ext.data.JsonReader({
                                    totalProperty: 'results',
                                    root: 'root',
                                        fields: [
                                                      {name:'locatorid', mapping:'locatorid'},
                                                      {name:'lname', mapping:'locatorid'},
                                                      {name:'shortname', mapping:'lname'},
                                                      {name:'x', mapping:'x'},
                                                      {name:'y', mapping:'y'},
                                                      {name:'regdate', mapping:'regdate'},
                                                      {name:'mapid', mapping:'mapid'},
                                                      {name:'state', mapping:'state'},
                                                      {name:'ground', mapping:'ground'}
                                                ]
                           })  
                     });
                   var sm = new Ext.grid.CheckboxSelectionModel();//checkbox
                   var cm = new Ext.grid.ColumnModel([
                        new Ext.grid.RowNumberer(),//显示行号
                        sm,
                        {header:'定位器号',dataIndex:'locatorid',width:100,sortable:true },
                        {header:'简称',dataIndex:'lname',width:100,sortable:true},
                        {header:'定位器名',dataIndex:'shortname',width:150,sortable:true},
                        {header:'X坐标',dataIndex:'x',align:'right',width:100,sortable:true},
                        {header:'Y坐标',dataIndex:'y',width:100,sortable:true},
                        {header:'注册时间',dataIndex:'regdate',width:150,sortable:true},
                        {header:'地图号',dataIndex:'mapid',width:100,sortable:true},
                        {header:'使用状态',dataIndex:'state',width:150,sortable:true},
                        {header:'设备性质',dataIndex:'ground',width:150,sortable:true}
                    ]);
                    
                var grid = new Ext.grid.GridPanel({
                height: 600,//不写的话,页面不报错误,也不显示数据
            store: store,
            cm: cm,
            sm: sm,
            autoEncode: true,
            bbar: new Ext.PagingToolbar({
                pageSize: 20, //每页显示几条数据
                store: store,
                displayInfo: true,
                displayMsg: '正在显示第 {0} 条至第 {1} 条数据,共 {2} 条数据',
                emptyMsg: "当前没有可以显示的数据"
       })
        });
         
        grid.render('grid-div');//让grid开始渲染
        store.load({params:{start:0, limit:20}});

   
    });
    </script>
</head>

<body>
    <div id="grid-div"></div>
    <div id="window_win"></div>
</body>
</html:html>

locator.do?method=initLocato 代码:
public ActionForward initLocator(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response) {
                    System.out.println("Hello ...");
                    LocatorVO vo=null;
                    LocatorBO bo=new LocatorBO();                    
                    response.setContentType("text/json; charset=utf-8");//防止乱码
                    String start = request.getParameter("start");
                   System.out.println(start);
                      String limit = request.getParameter("limit");
                      System.out.println(limit);
                      StringBuffer sb=new StringBuffer();
                    try{
                             int index = Integer.parseInt(start);
                              int pageSize = Integer.parseInt(limit);
                              List list=bo.locatorResults();
                              sb.append("{results:"+list.size()+",root:[");
                        for(int i=index;i<pageSize+index;i++){
                              vo=(LocatorVO)list.get(i);
                              sb.append("{locatorid:"+vo.getLocatorid()+",lname:'"+vo.getLname()+"',shortname:'"+vo.getShortname()+"',x:'"+vo.getX());
                              sb.append("',y:'"+vo.getY()+"',regdate:'"+vo.getRegdate()+"',mapid:'"+vo.getMapid()+"',state:'"+vo.getState()+"',ground:'"+vo.getGround()+"'}");
                              if(i !=pageSize+index-1){
                                      sb.append(",");
                              }
                        }
                        sb.append("]}");
                        System.out.println(sb.toString());
                        response.getWriter().write(sb.toString());
                    }catch(Exception e){
                            log.error("==获取定位器信息并处理成Json错误==",e);
                    }            
                return null;
         }




在页面上显示的时候,只能表头和分页标签的左边部分

分析:
   System.out.println(start);   System.out.println(limit);
   因为start和limit都为null,所以不进入for循环,也就不能生成json格式的的字符串,所以
   页面上不能显示数据,请问这么解决?
jianfeng008cn 2008-05-31
没遇到过哦 肯定是没发出去啦
demo_3312 2008-05-31
这样的问题,还真是不知道这么调试
郁闷
sunxing007 2008-06-02
我没有碰到这个问题,看我的测试代码。是在Spring框架下的。测试顺利
不过我在上面加了一个带搜索的panel,可以忽略它。但愿对你解决问题有帮助
    Ext.onReady(function(){
        Ext.QuickTips.init();
        var ds = new Ext.data.Store({
            proxy  : new Ext.data.HttpProxy( {url:'<%=request.getContextPath()%>/extjs.htm'} ),
            //sortInfo:{field: 'customerid', direction: "ASC"},
            reader : new Ext.data.JsonReader({
                    root:'root',
                    totalProperty:'totalCount',
                    id: 'OrderID'
                },
                [
                    {name : 'OrderID',mapping: 'OrderID'},
                    //we can ignore some columns that we don't need it.
                    //{name : 'CustomerID',mapping: 'CustomerID'},
                    {name : 'OrderDate',mapping: 'OrderDate'},
                    {name : 'Freight',mapping: 'Freight'},
                    {name : 'ShipRegion',mapping: 'ShipRegion'}
                ]
            ),
            // when open remoteSort, the sort function will implement at server .
            remoteSort:false
        });
        var fm = Ext.form;
        var colModel =  new Ext.grid.ColumnModel([
            {id:'OrderID',header:'OrderID',sortable: true, dataIndex: 'OrderID'},
            //{header : 'CustomerID',sortable: true, dataIndex: 'CustomerID'},
            {header : 'OrderDate',sortable: true,dataIndex:'OrderDate'},
            {header : 'Freight',sortable: true, dataIndex: 'Freight'},
            {header : 'ShipRegion',sortable: true, dataIndex: 'ShipRegion'}
        ]);
        
        var s_panel = new Ext.FormPanel({
            baseCls: 'x-plain',
            defaults: {width: 150},
            defaultType: 'textfield',
            height: 18,
            items: [{
                    fieldLabel: 'Search',
                    id:'title',
                    name: 'title'
            }]
        });
        
        var grid = new Ext.grid.GridPanel({
            el:'MyPageGrid',
            store: ds, 
            cm: colModel,
            autoExpandColumn: 'OrderID',
            renderTo: document.body,
            height:350,
            width:600,
            title:'Array Grid',
            loadMask: {msg:'Data loading,please wait......'},
            tbar:[
                s_panel,
                {
                    text: 'Go',
                    pressed: false,
                    handler: function(){
                        ds.load({
                            params: {start: 10, limit: 20, title: Ext.get('title').dom.value}
                        });
                    }
                }
            ],
            bbar: new Ext.PagingToolbar({
                pageSize: 20,
                store: ds,
                displayInfo: true,
                displayMsg: 'current: {0}-{1}records. There are {2} records',
                emptyMsg: "No record"
            }),
            viewConfig: {forceFit:true},
            sm: new Ext.grid.RowSelectionModel({singleSelect:true}),
            draggable: {
                //Config option of Ext.Panel.DD class.
                //It's a floating Panel, so do not show a placeholder proxy in the original position.
                insertProxy: false,
                // Called for each mousemove event while dragging the DD object.
                onDrag : function(e){
                    var pel = this.proxy.getEl();
                    this.x = pel.getLeft(true);
                    this.y = pel.getTop(true);
                    var s = this.panel.getEl().shadow;
                    if (s) {
                        s.realign(this.x, this.y, pel.getWidth(), pel.getHeight());
                    }
                },
                endDrag: function(e){
                    this.panel.setPosition(this.x, this.y);
                }

            },
            enableDragDrop: true,
            frame: true,
            stripeRows: true,
            ddText: 'You select {0} row(s)',
            buttons: [{text:'Save'},{text:'Cancel'}],
            buttonAlign:'center'
        });
        
        grid.render();
        ds.load({params:{start:0,limit:20}});
        grid.getSelectionModel().selectFirstRow();
});

上面 extjs.htm 是在spring配置文件中定义的bean,对应下面的Controller.

后台Controller:继承自AbstractController, 你可以用Map map = request.getParameterMap();debug去看看到底传进来的是一些什么参数.

public class Extjs extends AbstractController 
{
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        //You can get the parameters map to see the parameters that passed from Ext page.
        //Map map = request.getParameterMap();
        int totalCount = 100;
        String _start = request.getParameter("start");
        String _limit = request.getParameter("limit");
        String sort = request.getParameter("sort");//get the sort colume name.
        String dir = request.getParameter("dir");  //the direct, value: DESC/ASC
        int start = Integer.parseInt(_start);
        int limit = Integer.parseInt(_limit);
        System.out.println("stsrt:" + _start +"\n" + "limit:" + _limit);
        StringBuffer sb = new StringBuffer();
        sb.append("[");
        for(int i=start;i<start+limit;i++){
            sb.append("{OrderID:'orderid" + i)
              .append("',CustomerID:'customerid" + i)
              .append("',OrderDate:'2008-08-08")
              .append("',Freight:'freight" + i)
              .append("',ShipRegion:'shipregion" + i)
              .append("'}");
            if(i!=start+limit-1){
                sb.append(",");
            }
        }
        sb.append("]");
        String temp = "{totalCount:"+totalCount+",root:" + sb.toString() + "}";
        response.setContentType("text/json");
        response.getWriter().println(temp);
        response.getWriter().flush();
        return null;
    }
} 
demo_3312 2008-06-05
谢谢。。。。
Global site tag (gtag.js) - Google Analytics