1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.uif.layout.collections;
17
18 import org.kuali.rice.krad.uif.UifConstants;
19 import org.kuali.rice.krad.uif.container.CollectionGroup;
20 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
21 import org.kuali.rice.krad.uif.view.View;
22 import org.kuali.rice.krad.web.form.UifFormBase;
23
24 import java.util.List;
25
26
27
28
29
30
31
32 public class CollectionPagingHelper {
33
34
35
36
37
38
39
40
41 public void processPagingRequest(View view, CollectionGroup collectionGroup, UifFormBase form, String page) {
42
43 synchronized (view) {
44 List<Object> modelCollection = ObjectPropertyUtils.getPropertyValue(form,
45 collectionGroup.getBindingInfo().getBindingPath());
46
47 int displayStart = collectionGroup.getDisplayStart();
48 int displayLength = collectionGroup.getDisplayLength();
49
50
51 if (page.equals(UifConstants.PageRequest.FIRST)) {
52 displayStart = 0;
53 } else if (page.equals(UifConstants.PageRequest.PREV)) {
54 displayStart = displayStart - displayLength;
55 } else if (page.equals(UifConstants.PageRequest.NEXT)) {
56 displayStart = displayStart + displayLength;
57 } else if (page.equals(UifConstants.PageRequest.LAST)) {
58 int lastPageSize = modelCollection.size() % displayLength;
59
60 if (lastPageSize != 0) {
61 displayStart = modelCollection.size() - lastPageSize;
62 } else {
63 displayStart = modelCollection.size() - displayLength;
64 }
65 } else {
66 displayStart = ((Integer.parseInt(page.trim()) - 1) * displayLength);
67 }
68
69 collectionGroup.setDisplayStart(displayStart);
70 }
71 }
72 }