Project and Portfolio Management Practitioners Forum
cancel

Custom java portlet. Pagination.

Highlighted
ieroglif
Respected Contributor.

Custom java portlet. Pagination.

Hi everyone.

 

I've created custom portlet(aka move requests in queue of urgency, drag & drop). Now I would like to implement pagination logic. Does somebody face  such kind of experience?

Best Regards,
Ieroglif.
2 REPLIES
gerardoquero197
Frequent Contributor.

Re: Custom java portlet. Pagination.

something hard to do, but so far it has worked the following:
1. I have created a class called Page
2. in this class have the methods needed to calculate it according to the requested information display ad

public void setTotalElements(int totalElements) { this.totalElements = totalElements; }

/**
*
* @param currentPage
* @param pageSize
* @return
*/
public static int getStartItemByPage(int currentPage, int pageSize) {
//System.out.println("currentPage " + currentPage + "pageSize" + pageSize );
return Math.max((pageSize * (currentPage - 1)) + 1, 1);
}

public static int getLastPage(int totalElements, int pageSize) {

int base = totalElements / pageSize;
int mod = totalElements % pageSize;
int lastpage = base + (mod > 0?1:0);
// System.out.println("getLastPage mod" + lastpage );
// System.out.println("getLastPage base" + base );
return base + (mod > 0?1:0);
}

3. The jsp paints the informa using this method of class PAGE
public List <RequestPsrDto> getPage (int page, int pageSize) {

int first = getStartItemByPage (page, pageSize);
List results = new ArrayList <RequestPsrDto> <RequestPsrDto> ();
List list = new ArrayList <RequestPsrDto> <RequestPsrDto> ();
DaoFactory df = null;
try {
df = DaoFactory.getInstance ();
ProjectPSRDao df.getRequestTypeDao RSPs = ();
list = psrs.getRequestList (this.project_id);

} catch (Exception e) {
System.out.println ("Error" + e.getStackTrace ());
e.printStackTrace ();
}

countAdds int = first; / / To keep track
/ / System.out.println ("countAdds" + countAdds);
while (! list.isEmpty () && (countAdds -1) <list.size ()) {
/ / System.out.println ("RECOVERING =" + (countAdds - 1));
results.add (list.get (countAdds - 1));
if (+ + countAdds> = (first + pageSize)) {
break;
}
}
totalElements int = list.size (); / / The last element
this.totalElements = totalElements;
int mod = this.getLastPage (this.totalElements, pageSize);
this.lastPage = mod;
/ / System.out.println ("totalElements" + this.totalElements);
/ / System.out.println ("totalElements mod" + mod);
if (totalElements == 0) {
this.page = 1;
this.lastPage = 1;
}
return results;
}

regards
Utkarsh_Mishra
Acclaimed Contributor.

Re: Custom java portlet. Pagination.

Not used in Custom Portlet, but implemented it in JSP report. I had used jquery for pagination.

 

You can try can give it a try.

Cheers..
Utkarsh Mishra

-- Remember to give Kudos to answers! (click the KUDOS star)