01: package dinamica;
02:
03: /**
04: * Generic transaction to provide a recordset
05: * containing the fields required to "paint"
06: * navigation controls for paged views.
07: *
08: * <br>
09: * Creation date: 29/10/2003<br>
10: * Last Update: 29/10/2003<br>
11: * (c) 2003 Martin Cordova<br>
12: * This code is released under the LGPL license<br>
13: * @author Martin Cordova
14: * */
15: public class PagingControls extends GenericTransaction {
16:
17: /* (non-Javadoc)
18: * @see dinamica.GenericTransaction#service(dinamica.Recordset)
19: */
20: public int service(Recordset inputParams) throws Throwable {
21:
22: int rc = super .service(inputParams);
23:
24: //get recordset ID
25: String recordsetID = (String) getRequest().getAttribute(
26: "paging.recordset");
27: String pageSize = (String) getRequest().getAttribute(
28: "paging.pagesize");
29:
30: //retrieve from session using this ID
31: Recordset rs = (Recordset) getSession().getAttribute(
32: recordsetID);
33:
34: //patch 2007-06-02 - paging view facilities for Ajax - requires default pagesize
35: if (pageSize != null && !pageSize.equals(""))
36: rs.setPageSize(Integer.parseInt(pageSize));
37:
38: //patch 2007-07-10 - paging view facilities for Ajax
39: //may want to navigate specific page after search
40: String currentPage = (String) getRequest().getParameter(
41: "currentpage");
42: if (currentPage != null && !currentPage.equals("")) {
43: int page = Integer.parseInt(currentPage);
44: //page must be in valid range
45: if (page > rs.getPageCount())
46: page = rs.getPageCount();
47: rs.getPage(page);
48: }
49:
50: //publish recordset
51: publish("paging.controls", rs.getRecordsetInfo());
52:
53: return rc;
54:
55: }
56:
57: }
|