如何在struts2动作类中发送或捕获dataTable 1.10参数 [英] how to send or capture dataTable 1.10 parameters in struts2 action class

查看:108
本文介绍了如何在struts2动作类中发送或捕获dataTable 1.10参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我正在使用struts2为我的Web应用程序。我启用了 bServerSide = true; 并调用sAjaxSource:PaginationAction。记录私人列表<收入> aaData; 正在填充jsp页面。但是我发现很难捕获上面指定的其他参数。这个输入的字符串到哪个动作类的变量。我在我期待的搜索框字符串的动作类中有一个变量 private String search;



请帮助我这个。我需要添加datatable1.10版本的任何jar文件到我的项目(我不知道如果我们有任何jar)。



这是我的JQuery代码: / p>

  var oTable = $(。IncomeTable)。dataTable({
paging:true,
search: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 ,可搜索:假,b可排序: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;
私人列表<收入> aaData;

注意:所有的整数值都将作为'$ code> 0 '和字符串变量为 null

解决方案

的Google搜索,我的上述帖子的结论如下:



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

  HttpServletRequest request = ServletActionContext.getRequest(); 
String searchFilterString = request.getParameter(search [value]);
// here String'search [value]'是由datatable发送的参数名称

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



下面是我用来修剪列表以支持我的数据记录的一段java代码。



int $ from int = 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;
}
其他
{
fromIndex =(int)(Math.ceil((start + 1)/ iDisplayLength)* iDisplayLength );
toIndex = fromIndex + iDisplayLength;
}
if(toIndex> getAaData()。size())
{
toIndex = getAaData() );
}
setAaData(getAaData()。subList(fromIndex,toIndex));


$ b $如果有任何人对上述发布和我的答案有任何疑问,请告诉我,我没有对上述JQuery代码做任何改动。



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



注意:不同的参数将为p如果您在jquery代码中使用 sAjaxSource 而不是 ajax ,则会对服务器进行评估。您可以在请求对象中了解datatable的参数。


I have a web application in which I am using DataTable version 1.10 to display the records and for pagination. I am new to DataTable. I am finding it difficult in capturing the parameters like search string in the search box of data table, Sort action,iTotalRecords,iTotalDisplayRecords,iDisplayLength etc etc.,

I am using struts2 for my web application. I have enabled the bServerSide=true; and calling "sAjaxSource" : "PaginationAction". the records private List<Income> aaData; are getting populated in jsp page. But I am finding it difficult to capture the other parameters as specified above. to which action class's variable does this entered string goes to.? I have a variable private String search; in my action class to which I am expecting the search box string should be assigned.

Please help me which this. Do I need to add any jar files of datatable1.10 version to my project( I am not sure If we have any jar).

Here is my JQuery Code:

 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}]
});

Action Class variables:

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;

Note: all the integer values are coming as '0' and string variables as null

解决方案

After several days of Google search, My version of conclusion for the above post is as below.

Conclusion: Strut2 will not automatically populate the values of datatable properties to action class's property. But the dataTable properties that are sent from the jsp page can be captured using the HttpServletRequest object. See the below code

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

Here is the link to the list of parameters sent to server from datatables and parameters sent from server to datatable

Below is the piece of java Code which I have used to trim the List to support my datatable records.

  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));

Let me know if any one have any doubts regarding the above post and my version of answer. I haven't done any change to the above mentioned JQuery code.

Any corrections and suggestion for the above post are greatly appreciated

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.

这篇关于如何在struts2动作类中发送或捕获dataTable 1.10参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆