Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
jQuery DataTables and J2EE web application integration[^]

Hi,

The above link have a example for Jquery DataTable.
In that they have loaded records to the table through list at a time. And when we click on next button it will display next 10 or 20 records.

But i'm looking a code like i should get the records from database and display,
And when i click on next button it should go and fetch next 10 or 20 records from database.


So please help me out in this. I'm new to this so please help me. i'll be looking for your answers
Posted
Updated 18-Jan-12 21:56pm
v5
Comments
TorstenH. 19-Jan-12 3:57am    
I added the correct link and the SQL tags - you need to address your DB correct, it's not so much about the Java code.
rohitVasu 19-Jan-12 5:02am    
hi, Where you have added that link and sql tags. And when i click on next button it will go and fetch next 10 or 20 records from database...???

1 solution

if you are using Struts2 it's quit easy.

just return list from you service class,

--------------------------------------------------------------------------------
public List yourmethod() {
Session session = Utils.HibernateUtil.getSessionFactory().openSession();
session.getTransaction().begin();
List list = new ArrayList();
try {
List qry = session.createCriteria(dao-class-name.class).list();
} catch (Exception e) {
}
return list;
}
---------------------------------------------------------------------------------
after getting list ,just iterate them..

public String gridsearchdata() {
Session session = hibernate.HibernateUtil.getSessionFactory().openSession();
session.beginTransaction();
try {
gridconst grdcns = new gridconst();
gridservice grdsrv = new gridservice();
gridModel = new ArrayList();
Iterator itr = grdsrv.gridsearch(sr, name, age, address, phoneNo).iterator();
while (itr.hasNext()) {
Griddata obj = (Griddata) itr.next();
gridModel.add(new gridconst(obj.getSr(), obj.getName(), obj.getAge(), obj.getAddress(), obj.getPhoneNo()));

}
} catch (Exception e) {
e.printStackTrace();
session.getTransaction().rollback();
}
return SUCCESS;
}
-----------------------------------------------
batter to use struts2 jquery grid,for struts2 jquery grid download jquery lib form
"http://code.google.com/p/struts2-jquery/downloads/detail?name=struts2-jquery-grid-plugin-2.5.3.jar&can=2&q="


jquery grid code

<sj:head xmlns:sj="#unknown">

XML
<s:url id="ticketgrid" action="ticketaction" namespace="/ticketassigning"/>
                <sjg:grid
                    id="Ticketassigngrid"
                    caption="Assign Ticket"
                    dataType="json"
                    href="%{ticketgrid}"
                    onSelectRowTopics="rowselect"
                    formIds="ticketForm"
                    gridModel="itemlist"
                    reloadTopics="refreshdgrid"
                    rownumbers="true"
                    width="1000"
                    height="150"
                    >
                    <sjg:gridColumn name="idTicketLogid" index="idTicketLogid" title="Ticket No" key="true"/>
                    <sjg:gridColumn name="loggedby" index="loggedby" title="Logged By" />
                    <sjg:gridColumn name="loggedDate" index="loggedDate" title="Logged Date" formatter="date"/>
                    <sjg:gridColumn name="location" index="location" title="Location"/>
                    <sjg:gridColumn name="idTicketSubCategoryCd" index="idTicketSubCategoryCd" title="Category" width="220"/>
                    <sjg:gridColumn name="ticketstatuslookup" index="ticketstatuslookup" title="Status" />
                    <sjg:gridColumn name="ticketPriority" index="ticketPriority" title="Priority" />
                    <sjg:gridColumn name="assignedTo" index="assignedTo" title="Assigned to"/>
                </sjg:grid>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900