首页 文章

如何在struts2动作类中发送或捕获dataTable 1.10参数

提问于
浏览
1

我有一个Web应用程序,我在其中使用DataTable版本1.10来显示记录和分页 . 我是DataTable的新手 . 我发现在数据表,排序操作,iTotalRecords,iTotalDisplayRecords,iDisplayLength等搜索框中捕获搜索字符串等参数很困难,

我在我的Web应用程序中使用struts2 . 我已启用 bServerSide=true; 并调用 "sAjaxSource" : "PaginationAction" . 记录 private List<Income> aaData; 将在jsp页面中填充 . 但我发现很难捕捉上面指定的其他参数 . 这个输入的字符串到哪个动作类的变量 . 我的动作类中有一个变量 private String search; ,我期望应该为其分配搜索框字符串 .

请帮我这个 . 我是否需要将datatable1.10版本的任何jar文件添加到我的项目中(我不确定如果我们有任何jar) .

这是我的JQuery代码:

var oTable=$(".IncomeTable").dataTable({
    "paging":true,
    "searching": true,
    "bProcessing" : true,
    "bServerSide" : true,
    "bJQueryUI" : true,
    "info":true,
    "bAutoWidth": false,
    "iDisplayLength": 10,
    "aLengthMenu": [[10, 15], [10, 15]],
    "sPaginationType" : "full_numbers",
    "ajax" : "PaginationAction",
    "aoColumns": [
         {"mData":"description","bSearchable": true,"bSortable": true},
         {"mData":"catergory.userCodeName","bSearchable": false,"bSortable": false},
         {"mData":"payee.payeeName","bSearchable": false,"bSortable": false},
         {"mData":"transactionDate","bSearchable": false,"bSortable": false},
         {"mData":"amount","sWidth":"30px","bSearchable": false,"bSortable": false}]
});

动作类变量:

private int iTotalRecords;
private int iTotalDisplayRecords;
private int iDisplayLength;
private String sEcho;
private String sColumns;
private String sSearch;
private String search;
private String sKeyword;
private List<Income> aaData;

注意:所有整数值都是' 0 ',字符串变量是 null

1 回答

  • 1

    经过几天的谷歌搜索,以上帖子的我的结论版本如下 .

    结论:Strut2不会自动将datatable属性的值填充到action类的属性 . 但是可以使用HttpServletRequest对象捕获从jsp页面发送的dataTable属性 . 请参阅以下代码

    HttpServletRequest request=ServletActionContext.getRequest();
    String searchFilterString=request.getParameter("search[value]");
    // here String 'search[value]' is the parameter name  sent by datatable
    

    Here是从数据表和从服务器发送到数据表的参数发送到服务器的参数列表的链接

    下面是我用来修剪List以支持我的数据表记录的java代码 .

    int fromIndex=0,toIndex=0;    
      int length=Integer.parserInt(request.getParamter("length"); 
      int start=Integer.parserInt(request.getParamter("start");
      int iDisplayLength=Integer.parserInt(request.getParamter("iDisplayLenght");
      if(length>0)
       {
       fromIndex=(int)(Math.ceil((start+1)/lenght)*length);
       toIndex=fromIndex+length;
       }
      else
      {
       fromIndex=(int)(Math.ceil((start+1)/iDisplayLength)*iDisplayLength);
       toIndex=fromIndex+iDisplayLength;
       }
      if(toIndex>getAaData().size())
      {
      toIndex=getAaData().size();
       }
     setAaData(getAaData().subList(fromIndex,toIndex));
    

    如果有人对上述帖子和我的答案版本有任何疑问,请告诉我 . 我没有对上面提到的JQuery代码做任何改动 .

    对上述帖子的任何更正和建议都非常感谢

    Note: Different parameters will be passes to server if you are usingsAjaxSource in stead of ajax in the jquery Code. You can get to know about the parameters of datatable in request object.

相关问题