Big news! The community will be moving to a new platform April 21. Read more.
Big news! The community will be moving to a new platform April 21. Read more.
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class
737 views

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.
0 Likes
2 Replies
Absent Member.. Absent Member..
Absent Member..

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
0 Likes
Cadet 2nd Class Cadet 2nd Class
Cadet 2nd Class

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)
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.