Using the jquery datatable is a really awesome thing when you have to display search results in an already sorted and paginated and searchable and..... the features just keep going on.
I spent some hours figuring using struts2 action class to return the values using ajax json object. Thought of sharing it..
I will start with the requirements:
1. struts2 framework application - Assuming you already have an application up and running. You can get a struts framework which has the dataTable jquery being used with a servlet here
2. struts2-json-plugin-2.1.8.jar - You can get the jar from the link. Put it in the lib folder of your struts application or add it to your project build path.
3. jquery dataTable plugin from here - JQuery DataTable
After downloading the dataTable zip file you just need few of the files if you are just using a basic version of the datatable.
Here are the files you would need from the zip extract:
i. \media\css\demo_page.css
ii. \media\css\demo_table.css
iii. \media\css\demo_table_jui.css
iv. \media\js\jquery.dataTables.min.js
v. \media\js\jquery.js
vi. /examples_support/themes/smoothness/jquery-ui-1.8.4.custom.css - Just for a theme. This is not required for a basic table.
search.jsp
struts.xml
SearchItemAction.java
BaseWebAction - To get the request which is required by the datatable
Company.java
DataRepository.java
DataTablesParamUtility.java
JQueryDataTableParamModel.java
And that would be enough. PS: The last 4 classes are from the sample workspace provided in the link above.
Start giving your page the stylish datatable in your struts framework!!!
Sample : DataTable_Struts2 - Maven based. Just run the pom and it will get the jar files required.