1. Create table in the web page
......
2. Initilize the table
$(document).ready(function(){
$('#example').dataTable();
});
3. Apply the jEditable handler to the table
$('td', oTable.fnGetNodes()).editable('editData.do', {
submit: 'Update',
cancel: 'Cancel',
indicator: '
',
', tooltip: "Click to edit...",
callback: function(new_value, settings){
var aPos = oTable.fnGetPosition(this);
oTable.fnUpdate(value, aPos[0], aPos[1] )
},
name: 'new_value',
submitdata: function(value, settings){
return {
"agency_id": this.parentNode.getAttribute('id'),
"column": oTable.fnGetPosition(this)[2]
};
}
});
4. Write Struts Action class
class EditDataAction {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Integer agencyId = Integer.parseInt(request.getParameter("agency_id"));
String newAgencyName = request.getParameter("new_value");
AgencyDAO a = new AgencyDAO();
a.updateAgency(agencyId, newAgencyName);
response.setContentType("text/text;charset=utf-8");
response.setHeader("cache-control", "no-cache");
PrintWriter out = response.getWriter();
out.println(newAgencyName);
out.flush();
return null;
}
}
5. Configure struts-config.xml
No comments:
Post a Comment