Skip to content

Instantly share code, notes, and snippets.

@neophob
Created April 10, 2013 15:11
Show Gist options
  • Save neophob/5355467 to your computer and use it in GitHub Desktop.
Save neophob/5355467 to your computer and use it in GitHub Desktop.
jsp taglib, lazy loading
struts-action config (configure webservice):
<action
path="/show_xxx_XHR"
type="xxx.webapp.action.XXX_XHRAction"
name="dummyForm"
scope="request"
input="failure"
parameter="method"
unknown="false"
validate="false"
roles="admin,support">
</action>
the webservice:
public class XXX_XHRAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {
log.debug("hello ajax!");
DatatablesCriterias dc = DatatablesCriterias.getFromRequest(request);
log.debug(dc);
List<AssetType> assetType = DAO CALL
Long count = 500L;
Long countFiltered = (long)assetType.size();
DataSet<AssetType> dataset = new DataSet<AssetType>(assetType, count, countFiltered);
DatatablesResponse<AssetType> resp = DatatablesResponse.build(dataset, dc);
//get output
response.setContentType("application/json");
PrintWriter out = response.getWriter();
//jackson converter
ObjectMapper mapper = new ObjectMapper();
mapper.writeValue(out, resp);
out.flush();
log.debug("done");
return null;
}
the jsp:
<datatables:table id="myTableId" data="${assetTypList}" cssClass="table table-striped" export="csv" url="/show_xxx_XHR.html" serverSide="true" processing="true" pipelining="true" pipeSize="6">
<datatables:column title="id" property="id" sortable="true" filterable="false"/>
<datatables:column title="name" property="name" sortable="true" filterable="true"/>
<datatables:export type="csv" includeHeader="false" fileName="my-export-name" cssClass="btn" label="CSV without header row" />
</datatables:table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment