Wednesday, July 28, 2010

Implementing Pagination in IBM MDM

Before you start implementing the pagination feature for your search functionality I recommend you to explore the pagination facility for one of the existing search service.
For eg: searchFSParty





Note that inside the <dwlcontrol>  I had placed a few things extra.
   <pagestartindex>1</pagestartindex>
   <pageendindex>3</pageendindex>
   <returnavailableresultcount>true </returnavailableresultcount>


Example 1
If the pageStartIndex is 1, the pageEndIndex is 10, and the total result count is 16, then 10 records will be returned in the first subset, and 6 records will be returned in the second subset.

Example 2
 If the pageStartIndex is 1, the pageEndIndex is 10, and the total result count is 8, then the pageEndIndex is considered to be equal to the total count, and 8 records will be returned in the set.

Now we are ready to implement the pagination in our custom search transactions.
(Please read about how to create a custom search in my previous post)


1. The user sends a request XML for searchCustomer(My custom search transaction) transactions including  the pagination parameters. 
Pagiantion Pramaters:

    <pagestartindex>1 </pagestartindex>
   <pageendindex>3</pageendindex> 
   <returnavailableresultcount>true </returnavailableresultcount>
(Will help you return the total number of records available on executing the query for your search.)

2. Inside the controller class for our searchCustomer/handlesearchCustomer we have to add response BObj class name in the DWLControl

 You will be having a method generated in you controller like the one below.
 public DWLResponse searchCustomer(xxxRequestBObj theBObj) throws DWLBaseException
 Add the following:
 Vector reponseBobsForTxn=new Vector(); reponseBobsForTxn.add("com.mycompany.xxxResponseBObj");
 theBObj.getControl().setResponseBObjsForTxn(reponseBobsForTxn);

Now come back to your component class:

3.Add the following just above your List list = bObjQuery.getResults();
boolean considerForPagination = PaginationUtils.considerForPagintion(xxxResponseBObj.class.getName(), theBObj.getControl());
theBObj.getControl().setConsiderForPagintionFlag(considerForPagination);
System.out.println("Start Index--"+theBObj.getControl().getPageStartIndex());
System.out.println("End Index---"+theBObj.getControl().getPageEndIndex());

Now you are done with the pagination implementation for you custom search.
To add to this if you want to restrict the size of the result set returned by a search transaction. Add the following line of code in your component class after you got the bObjQuery.
bObjQuery.setMaxResults(int);

What I had done to configure the max result count is add a 'maxresults' tag to my custom request object so that the user can configure the max results returned.





No comments:

Post a Comment