2016-01-04 19 views
1

我有一個Web應用程序,我在其中使用DataTable版本1.10來顯示記錄和分頁。我是DataTable的新手。我發現在數據表,排序操作,iTotalRecords,iTotalDisplayRecords,iDisplayLength等搜索框中捕獲搜索字符串等參數非常困難,我使用struts2作爲我的web應用程序。我已啓用bServerSide=true;並致電"sAjaxSource" : "PaginationAction"。記錄private List<Income> aaData;正在jsp頁面中填充。但是我發現很難捕獲上面指定的其他參數。操作類的變量是否輸入了該字符串?我在我的操作類中有一個變量private String search;,我期待搜索框字符串應該被分配。如何發送或捕獲dataTable 1.10參數struts2行動類

請幫我這個。我需要添加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

後幾天的Google搜索,我對上述帖子的結論如下。

結論:Strut2不會自動將數據表屬性的值填充到動作類的屬性。但是可以使用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是鏈接到從服務器發送到數據表

下面從數據表和參數發送到服務器的參數列表中,我已經習慣了修剪一塊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代碼做任何改變。

對上述職位的任何更正和建議是極大的讚賞

注:不同的參數會傳遞到服務器,如果你在的ajax代替在jQuery代碼使用sAjaxSource。您可以在request對象中瞭解datatable的參數。

相關問題