【问题标题】:Ajax datatable Server-side processing drawAjax数据表服务端处理绘制
【发布时间】:2018-07-17 08:59:16
【问题描述】:

在服务器端处理期间,从服务器“draw”发送的参数之一为 null,但我无法弄清楚在哪种情况下该参数从服务器发送为 null,有没有人遇到过这种情况之前的问题,我尝试通过应用程序导航,但我无法复制此问题,仅遇到过一次此问题,但无法重现。

基本上,我们的应用程序中有一个数据表,其中数据通过 ajax 调用填充,但在其中一种场景中,“draw”参数从服务器发送为 null。

【问题讨论】:

  • 您是否因为这个null 值而出现任何错误?
  • 问题已编辑:实际上,参数 "draw" 是在其中一种情况下从服务器作为空值发送的(而不是像我在编辑之前的问题中提到的那样发送到服务器时) .
  • 我们的代码没有处理 null 条件,因此我们在 UI 中收到数据表错误。由于这是一个生产问题,我们不允许在没有确定问题的情况下更改代码,我们只需要添加一个空检查来解决这个问题,我的问题是是否有任何特殊情况下“draw”参数是从服务器发送为 null。
  • 你能不能给一些你的代码
  • 这是用于服务器端处理的 ftl 文件(类似于 HTML 文件)的内容:

标签: ajax datatable


【解决方案1】:
    This is the content of the ftl file(similar to HTML file) which is used server side processing :

"processing": true,
stateSave: true,
"serverSide": true,
"pageLength": 10,
                "lengthMenu": [10, 25, 50, 100],"pagingType": "full_numbers",
                "scrollX": "true","scrollY": 500,
                "ajax": {
                    "url": "/platform/${registry}/facility${facilityId}/case-list/load",
                    "type": 'POST',
                    "data": function (d) {
                        d.visibleColumns = getVisibleColumns();
                    },
                    headers: {
                        'X-CSRF-Token': $('meta[name="_csrf"]').attr('content')
                    }
                },

    There is a code in the same ftl file where the application is manually sending the parameters to the server:
    var url = "/platform/${registry}/facility${facilityId}/case-list/export?output=excel&draw=1&start=0&length=100000";

    Though we are not doing anything with these paramerters in the controller class(Spring MVC contoller)

    This is the code in the java class, which is trying to read this parameter value and parsing it to int , since "req.getParameter("draw")" value is null, its throwing NumberFormatException in the code, but not able to replicate in which scenario.

    public int getDraw() {
        return Integer.parseInt(req.getParameter("draw"));
      }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-06
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-16
    相关资源
    最近更新 更多