JQGrid不显示某些列的值以及其他列的值是否正确显示

时间:2015-03-01 06:07:59

标签: mysql hibernate spring-mvc jqgrid

我正在为我的Web应用程序使用Spring MVC,Hibernate,MySQL,JSP和JQGrid。在尝试实现一个页面时,我遇到了如下所述的奇怪行为:

  1. 传递给JSP的JSON数据是正确的,并且在所有列中都有效
  2. 但是,在28列中,数据以21列正确显示,但在7列中,数据根本不显示。这7列是前4个,其他3个位于中间。
  3. js-for-acctmst.js文件的相关部分如下:

     grid.jqGrid({ 
         datatype: 'json', 
         mtype: 'GET', 
         height: 'auto',
         url:'/NioERPJ/admin/acctmstmgmt/',
         editurl:'/NioERPJ/admin/acctmstmgmt/edit',
         colNames:['Company Code','A/c Code','A/c Description','BA Code', 'Sched', 'Rel. Code', 'Header', 'BPTA', 'Perc.', 'T_O_AC', 'Op.Cr.', 'Op.Dr.', 'Sgn', 'Fnd', 'Ledger', 
                    'LedgerSum', 'DFlag', 'Tran Dr.', 'Tran Cr.', 'OutField', 'Gross', 'Net', 'SFlag', 'SaleCD', 'Add3', 'DateOP Dr.', 'DateOP Cr.', 'Username'],
            colModel:[
                {name:'co_code',index:'co_code',editable:true,edittype:'select',editoptions:{dataUrl:"/NioERPJ/admin/acctmstmgmt/listCmps"},formoptions:{elmprefix:'*'}},
                {name:'acc_code',index:'acc_code', width:50, editable:true, editrules:{required:true}, editoptions:{size:7}, formoptions:{elmprefix:'*'}},
                {name:'acc_des',index:'acc_des', width:100, editable:true, editrules:{required:true}, editoptions:{size:100}, formoptions:{elmprefix:'*'}},
                {name:'ba_code',index:'ba_code', width:50, editable:true, editrules:{required:true}, editoptions:{size:8}, formoptions:{elmprefix:'*'}},
                {name:'sched',index:'sched', width:50, editable:true, editrules:{required:true}, editoptions:{size:10}, formoptions:{elmprefix:'*'}},
                {name:'rel_code',index:'rel_code', width:50, editable:true, editrules:{required:true}, editoptions:{size:10}, formoptions:{elmprefix:'*'}},
                {name:'header',index:'header', width:50, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
                {name:'bpta',index:'bpta', width:50, editable:true, editrules:{required:true}, editoptions:{size:10}, formoptions:{elmprefix:'*'}},
                {name:'perc',index:'perc', width:50, template : numberTemplate},
                {name:'t_o_ac',index:'t_o_ac', width:50, editable:true, editrules:{required:true}, editoptions:{size:1}, formoptions:{elmprefix:'*'}},
                {name:'op_cr',index:'op_cr', width:50, template : numberTemplate},
                {name:'op_dr',index:'op_dr', width:50, template : numberTemplate},
                {name:'sgn',index:'sgn', width:100, editable:true, editrules:{required:true}, editoptions:{size:30}, formoptions:{elmprefix:'*'}},
                {name:'fnd',index:'fnd', width:50, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
                {name:'ledger',index:'ledger', width:50, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
                {name:'ledgersum',index:'ledgersum', width:50, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
                {name:'dflag',index:'dflag', width:50, editable:true, editrules:{required:true}, editoptions:{size:30}, formoptions:{elmprefix:'*'}},
                {name:'tran_dr',index:'tran_dr', width:50, template : numberTemplate},
                {name:'tran_cr',index:'tran_cr', width:50, template : numberTemplate},
                {name:'out_field',index:'out_field', width:50, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
                {name:'gross',index:'gross', width:50, template : numberTemplate},
                {name:'net',index:'net', width:50, template : numberTemplate},
                {name:'sflag',index:'sflag', width:50, editable: true,edittype:"checkbox",editoptions: {value:"Yes:No"}},
                {name:'salecd',index:'salecd', width:50, editable:true, editrules:{required:true,number:true}, editoptions:{size:10}, formoptions:{elmprefix:'*'}},
                {name:'add3',index:'add3', width:100, editable:true, editrules:{required:true}, editoptions:{size:30}, formoptions:{elmprefix:'*'}},
                {name:'dateop_dr',index:'dateop_dr', width:50, template : numberTemplate},
                {name:'dateop_cr',index:'dateop_cr', width:50, template : numberTemplate},
                {name:'username',index:'username', width:100, editable:true, editrules:{required:true}, editoptions:{size:30}, formoptions:{elmprefix:'*'}}
            ],
         gridview: true,
         toolbar: [false, "bottom"],
         pager: $('#pager'), 
         rowNum:15, 
         rowList:[10,20,30], 
         sortname: 'acc_code', 
         sortorder: "asc", 
         viewrecords: true,
         altRows: false, 
         autowidth:true, 
         shrinkToFit:false,
         forceFit:true,
         jsonReader : {
             root: "rows",
             page: "page",
             total: "total",
             records: "records",  
             repeatitems: false
            },        
    

    控制器文件'Acctmstcontroller.java'如下:

    package com.nej.controller;
    
        @Controller
       @RequestMapping(value={"/admin/acctmstmgmt"})
       public class AcctMstController {
    @Autowired
    private AcctMstService acctmstService;
    
    @Autowired
    private CompanyMstService companymstService;
    
    @RequestMapping(value="/open")         
    public ModelAndView opAcctmstmgmt(){
        ModelAndView model = new ModelAndView();
    model.setViewName("/admin/acctmstmgmt");
    return model;
    } 
    
    @RequestMapping(method=RequestMethod.GET, produces="application/json")         
    public @ResponseBody  AcctMstResponse getAll(
            @RequestParam("_search") Boolean search,
            @RequestParam(value="filters", required=false) String filters,
            @RequestParam(value = "rows", required=false) Integer rows, 
            @RequestParam(value = "page", required=false) Integer page, 
            @RequestParam(value = "sidx", required=false) String sidx, 
            @RequestParam(value = "sord", required=false) String sord, 
            HttpServletRequest request) {
    
        if (search == true) {
            return getFilteredRecords(filters, rows,page, sidx, sord);
    }
    
    
         List<AcctMst> list = null;
         list = acctmstService.getAcctMsts(rows,page, sidx, sord);
         AcctMstResponse response = new AcctMstResponse();
         response.setRows(list);
         int count = acctmstService.getNoOfRecords();
         int total = count%rows == 0 ? (int)Math.ceil(count/rows) : (int)Math.ceil(count/rows)+1;
         response.setTotal(total);
         response.setRecords(count);
         response.setPage(page);
         return response;
     }
    
    public AcctMstResponse getFilteredRecords(String filters, Integer rows, Integer page, String sidx, String sord) {
    
            List<AcctMst> list = null;
            list = acctmstService.searchAcctMsts(filters,rows,page, sidx, sord);
    
            AcctMstResponse response = new AcctMstResponse();
            response.setRows(list);
            int count = acctmstService.getNoOfRecords();
            int total = count%rows == 0 ? (int)Math.ceil(count/rows) : (int)Math.ceil(count/rows)+1;
            response.setTotal(total);
            response.setRecords(count);
            response.setPage(page);
            return response;
    }
    
     @RequestMapping(value="/edit")
     public ModelAndView doEdit(HttpServletRequest request) {
    
        Byte co_code = 0;
        String acc_code = null;
        String acc_des = null;
        String ba_code = null;
        String sched = null;
        String rel_code = null;
        boolean header = false;
        String bpta = null;
        double perc = 0.00d;
        String t_o_ac = null;
        double op_cr = 0.00d;
        double op_dr = 0.00d;
        String sgn = null;
        boolean fnd = false;
        boolean ledger = false;
        boolean ledgersum = false;
        String dflag = null;
        double tran_dr = 0.00d;
        double tran_cr = 0.00d;
        boolean out_field = false;
        double gross = 0.00d;
        double net = 0.00d;
        boolean sflag = false;
        String salecd = null;
        double add3 = 0.00d;
        double dateop_dr = 0.00d;
        double dateop_cr = 0.00d;
        String username = null;
        String oper = null;
    
    
         Enumeration<String> paramNames = request.getParameterNames();
         while(paramNames.hasMoreElements()){
             String s = paramNames.nextElement();
    
             if("co_code".equalsIgnoreCase(s)){
                 co_code = Byte.parseByte(request.getParameter("co_code"));
             }else if("acc_code".equalsIgnoreCase(s)){
                 acc_code = request.getParameter("acc_code");
             }else if("acc_des".equalsIgnoreCase(s)){
                 acc_des = request.getParameter("acc_des");
             }else if("ba_code".equalsIgnoreCase(s)){
                 ba_code = request.getParameter("ba_code");
             }else if("sched".equalsIgnoreCase(s)){
                 sched = request.getParameter("sched");
             }else if("rel_code".equalsIgnoreCase(s)){
                 rel_code = request.getParameter("rel_code");
             }else if("header".equalsIgnoreCase(s)){
                 header = Boolean.parseBoolean(request.getParameter("header"));
             }else if("bpta".equalsIgnoreCase(s)){
                 bpta = request.getParameter("bpta");
             }else if("perc".equalsIgnoreCase(s)){
                 perc = Double.parseDouble(request.getParameter("perc"));
             }else if("t_o_ac".equalsIgnoreCase(s)){
                 t_o_ac = request.getParameter("t_o_ac");
             }else if("op_cr".equalsIgnoreCase(s)){
                 op_cr = Double.parseDouble(request.getParameter("op_cr"));
             }else if("op_dr".equalsIgnoreCase(s)){
                 op_dr = Double.parseDouble(request.getParameter("op_dr"));
             }else if("sgn".equalsIgnoreCase(s)){
                 sgn = request.getParameter("sgn");
             }else if("fnd".equalsIgnoreCase(s)){
                 fnd = Boolean.parseBoolean(request.getParameter("fnd"));
             }else if("ledger".equalsIgnoreCase(s)){
                 ledger = Boolean.parseBoolean(request.getParameter("ledger"));
             }else if("ledgersum".equalsIgnoreCase(s)){
                 ledgersum = Boolean.parseBoolean(request.getParameter("ledgersum"));
             }else if("dflag".equalsIgnoreCase(s)){
                 dflag = request.getParameter("dflag");
             }else if("tran_dr".equalsIgnoreCase(s)){
                 tran_dr = Double.parseDouble(request.getParameter("tran_dr"));
             }else if("tran_cr".equalsIgnoreCase(s)){
                 tran_cr = Double.parseDouble(request.getParameter("tran_cr"));
             }else if("out_field".equalsIgnoreCase(s)){
                 out_field = Boolean.parseBoolean(request.getParameter("out_field"));
             }else if("gross".equalsIgnoreCase(s)){
                 gross = Double.parseDouble(request.getParameter("gross"));
             }else if("net".equalsIgnoreCase(s)){
                 net = Double.parseDouble(request.getParameter("net"));
             }else if("sflag".equalsIgnoreCase(s)){
                 sflag = Boolean.parseBoolean(request.getParameter("sflag"));
             }else if("salecd".equalsIgnoreCase(s)){
                 salecd = request.getParameter("salecd");
             }else if("add3".equalsIgnoreCase(s)){
                 add3 = Double.parseDouble(request.getParameter("add3"));
             }else if("dateop_dr".equalsIgnoreCase(s)){
                 dateop_dr = Double.parseDouble(request.getParameter("dateop_dr"));
             }else if("dateop_cr".equalsIgnoreCase(s)){
                 dateop_cr = Double.parseDouble(request.getParameter("dateop_cr"));
             }else if("username".equalsIgnoreCase(s)){
                 username = request.getParameter("username");
             }else if("oper".equalsIgnoreCase(s)){
                 oper = request.getParameter("oper");
             }
         }
        Map<String, String> model = new HashMap<String, String>();
         if("edit".equalsIgnoreCase(oper)){
             AcctMst acctmst = new AcctMst();
             acctmst.setAcccode(acc_code);
             acctmst.setAccdes(acc_des);
             acctmst.setAdd3(add3);
             acctmst.setBacode(ba_code);
             acctmst.setBpta(bpta);
             acctmst.setCocode(co_code);
             acctmst.setDateopcr(dateop_cr);
             acctmst.setDateopdr(dateop_dr);
             acctmst.setDflag(dflag);
             acctmst.setFnd(fnd);
             acctmst.setGross(gross);
             acctmst.setHeader(header);
             acctmst.setLedger(ledger);
             acctmst.setLedgersum(ledgersum);
             acctmst.setNet(net);
             acctmst.setOpcr(op_cr);
             acctmst.setOpdr(op_dr);
             acctmst.setOutfield(out_field);
             acctmst.setPerc(perc);
             acctmst.setRelcode(rel_code);
             acctmst.setSalecd(salecd);
             acctmst.setSched(sched);
             acctmst.setSflag(sflag);
             acctmst.setSgn(sgn);
             acctmst.setToac(t_o_ac);
             acctmst.setTrancr(tran_cr);
             acctmst.setTrandr(tran_dr);
             acctmst.setUsername(username);
             acctmstService.updateAcctMst(acctmst);
         }else if("add".equalsIgnoreCase(oper)){
             AcctMst acctmst = acctmstService.getAcctMst(co_code, acc_code);
             if(acctmst == null){
                acctmst = new AcctMst();
                acctmst.setCocode(co_code);
                acctmst.setAcccode(acc_code);
                acctmst.setAccdes(acc_des);
                acctmst.setBacode(ba_code);
                acctmst.setSched(sched);
                acctmst.setRelcode(rel_code);
                acctmst.setHeader(header);
                acctmst.setBpta(bpta);
                acctmst.setPerc(perc);
                acctmst.setToac(t_o_ac);
                acctmst.setOpcr(op_cr);
                acctmst.setOpdr(op_dr);
                acctmst.setSgn(sgn);
                acctmst.setFnd(fnd);
                acctmst.setLedger(ledger);
                acctmst.setLedgersum(ledgersum);
                acctmst.setDflag(dflag);
                acctmst.setTrandr(tran_dr);
                acctmst.setTrancr(tran_cr);
                acctmst.setOutfield(out_field);
                acctmst.setGross(gross);
                acctmst.setNet(net);
                acctmst.setSflag(sflag);
                acctmst.setSalecd(salecd);
                acctmst.setAdd3(add3);
                acctmst.setDateopdr(dateop_dr);
                acctmst.setDateopcr(dateop_cr);
                acctmst.setUsername(username);
                acctmstService.saveAcctMst(acctmst);
             }else{
                 throw new RuntimeException();
             }
         }else if("del".equalsIgnoreCase(oper)){
             acctmstService.deleteAcctMst(co_code, acc_code);
         }
         return new ModelAndView("admin/acctmstmgmt",model);
     }
    
  4. 我无法解决为什么某些列未在JQGrid中显示的问题? PL。帮助

    我正在添加来自apache日志的以下调试输出

      

    DEBUG o.h.internal.util.EntityPrinter -   com.nej.acctmst.model.AcctMst {rel_code = 2,tran_dr = 2.0,perc = 2.0,   bpta = 2,dateop_cr = 2.0,acc_des = Test - 2,out_field = true,sflag = true,   sgn = 2,net = 2.0,fnd = true,op_cr = 2.0,add3 = 2.0,ledger = true,dflag = 2,   gross = 2.0,tran_cr = 2.0,ledgersum = true,salecd = 2,dateop_dr = 2.0,   sched = 2,header = false,op_dr = 2.0,t_o_ac = 2,ba_code = 2,   username = Test-2} 18:39:23.163 [http-apr-8080-exec-25] DEBUG   o.h.internal.util.EntityPrinter -   com.nej.acctmst.model.AcctMst {rel_code = 1,tran_dr = 1.0,perc = 1.0,   bpta = 1,dateop_cr = 1.0,acc_des =测试帐户,out_field = true,   sflag = false,sgn = 1,net = 1.0,fnd = true,op_cr = 1.0,add3 = 1.0,   ledger = true,dflag = 1,gross = 1.0,tran_cr = 1.0,ledgersum = true,   salecd = 1,dateop_dr = 1.0,sched = 1,header = true,op_dr = 1.0,t_o_ac = 1,   ba_code = 1,用户名=测试}

    我已经安装了Fiddler,并为JSON找到了以下输出

    {"rows":[
    {"sched":"1","header":true,"bpta":"1","perc":1.0,"sgn":"1","fnd":true,"ledger":true,
    "ledgersum":true,"dflag":"1","gross":1.0,"net":1.0,"sflag":false,"salecd":"1",
    "add3":1.0,"username":"Test","opdr":1.0,"opcr":1.0,"toac":"1","dateopdr":1.0,
    "acccode":"1","cocode":1,"accdes":"Test Account","bacode":"1","dateopcr":1.0,
    "trancr":1.0,"outfield":true,"trandr":1.0,"relcode":"1"},
    {"sched":"2","header":false,"bpta":"2","perc":2.0,"sgn":"2","fnd":true,"ledger":true,
    "ledgersum":true,"dflag":"2","gross":2.0,"net":2.0,"sflag":true,"salecd":"2",
    "add3":2.0,"username":"Test-2","opdr":2.0,"opcr":2.0,"toac":"2","dateopdr":2.0,
    "acccode":"2","cocode":2,"accdes":"Test - 2","bacode":"2","dateopcr":2.0,
    "trancr":2.0,"outfield":true,"trandr":2.0,"relcode":"2"}
    ],
    "total":1,
    "records":2,
    "page":1
    }
    

    从输出中可以看出,字段的顺序已更改,并且字段的名称与colModel中的字段名称不同(在某些字段中,下划线已被删除)。我的诊断是否正确?

1 个答案:

答案 0 :(得分:0)

在@Oleg的广泛帮助和指导下,我可以得出结论,传递给我的jsp文件的JSON数据没有正确形成。字段名称的顺序不同,下划线字符也已从中删除。这就是我的.jsp文件中没有显示某些字段的原因。