Development tools : XUI editor : Editing an XUI page : Editing the properties of a table : Adding a paginated table widget sample : Extending a business operation for a paginated table sample
  
Extending a business operation for a paginated table sample
This section provides a sample of how to extend a business operation for a paginated table. After the business operation for a paginated table is created, the business operation is available for selection for the operationNameForPagination property in the Pagination tab of the Properties view.
To extend a business operation for a paginated table
1 Create a new .operation file, and in the Filename field, enter PaginationBusinessOp.
2 In the Data tab of the PaginationBusinessOp operation file, create data elements. Create the following two root kColl data elements:
pageRetrieverData
item
3 For the pageRetrieverData root kColl, create the following field data elements as child elements:
start
count
totalRowNumber
enableNext
enablePrevious
errMsg
sort
rowsPerPage
pageNumber
pageEvent
4 For the pageRetrieverData root kColl, create a refData element as a child element. In the RefId field for the refData element, select item.
5 For the pageRetrieverData root kColl, create an iColl element as a child element. In the id field for the iColl, enter items.
6 For the items child iColl, create a refData element as a child element. In the RefId field for the refData element, select item.
7 For the item root kColl, create the following two field data elements as child elements:
name
address
The structure of the data for the PaginationBusinessOp operation is shown here:
<context id="pageRetrieverCtx" type="op">
  <refKColl refId="pageRetrieverData"/>
</context>
<kColl id="pageRetrieverData" dynamic="false">
  <field id="start" value="0"/>
  <field id="count" value="15"/>
  <field id="totalRowNumber" value="101"/>
  <field id="enableNext" value="true"/>
  <field id="enablePrevious" value="false"/>
  <field id="errMsg"/>
  <field id="sort"/>
  <field id="rowsPerPage" value="25"/>
  <field id="pageNumber" value="1"/>
  <field id="pageEvent"/>
  <refData refId="item"/>
  <iColl id="items">
    <refData refId="item"/>
  </iColl>
</kColl>
<kColl id="item">
  <field id="name" value="1"/>
  <field id="address" value="a"/>
</kColl>
8 Set the pagination table control logic in the business operation. For example:
IndexedCollection tableData = (IndexedCollection) this.getContext().getKeyedCollection().getElementAt("items");
tableData.removeAll();
Context ctx = getContext();
int size = Integer.parseInt(ctx.getValueAt("rowsPerPage").toString());
int pageNumber = Integer.parseInt(ctx.getValueAt("pageNumber").toString());
if (ctx.getValueAt("pageEvent") != null) {
if ("next".equalsIgnoreCase(ctx.getValueAt("pageEvent").toString())) {
pageNumber++;
} else {
pageNumber--;
}
}
for (int i = 0; i < size; i++) {
KeyedCollection tableKColl = (KeyedCollection) tableData.createElement(false);
tableKColl.setValueAt("name", "BTT"+rand.nextInt());
tableKColl.setValueAt("address", "CDL"+rand.nextInt());
tableData.addElement(tableKColl);
}
int total = Integer.parseInt(ctx.getValueAt("totalRowNumber").toString());
int pageSize = total / size;
if (total % size > 0) {
pageSize++;
}
ctx.setValueAt("totalRowNumber", total);
ctx.setValueAt("pageNumber", pageNumber);

if (pageNumber <= 1) {
ctx.setValueAt("enableNext", "true");
ctx.setValueAt("enablePrevious", "false");
} else if (pageNumber == pageSize) {
ctx.setValueAt("enableNext", "false");
ctx.setValueAt("enablePrevious", "true");
} else {
ctx.setValueAt("enableNext", "true");
ctx.setValueAt("enablePrevious", "true");
}
}
Go up to
Adding a paginated table widget sample