Liferay is a Gartner Magic Quadrant Leader for the Sixth Year! Find out why

Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Laura Liparulo
Search container with form parameter - pagination problem SOLVED
29 gennaio 2013 7.11
Risposta

Laura Liparulo

Punteggio: Junior Member

Messaggi: 38

Data di Iscrizione: 30 giugno 2012

Messaggi recenti

Hello, guys!
I've been struggling for a couple of days trying to make my seach container pagination works.
When you clicking on the next page and you need to use a form parameter value submitted to get the rows, you need to store it in the portlet preferences, otherwise you lose it in the page "refresh".

I haven't found a solution on the web so far, so I'm posting my code snippets... that WORKS lol:
but I'm using portlet preferences ... check it out!

action method in the controller:

 1        public void searchVolume(ActionRequest request, ActionResponse response)
 2            throws IOException, PortletException, PortalException,
 3            SystemException, NoSuchVolumeException {
 4
 5        String volumeIdentifier = request.getParameter("volumeId");
 6        long volumeId = (long) Integer.parseInt(volumeIdentifier);
 7        long idVol = 0;
 8
 9        boolean found = false;
10        boolean emptyList = false;
11
12        List<Volume> volume = new ArrayList<Volume>();
13        volume = VolumeLocalServiceUtil.getAllVolumes();
14        List<CaseArchive> caseArchive = new ArrayList<CaseArchive>();
15        caseArchive = CaseArchiveLocalServiceUtil
16                .getAllCasesbyVolumeId(volumeId);
17
18        if (caseArchive.size() == 0) {
19            emptyList = true;
20        }
21
22        for (Volume itemVolume : volume) {
23            if (itemVolume.getVolumeId() == volumeId)
24                found = true;
25        }
26
27        if (found && emptyList) {
28            SessionMessages.add(request, "no-cases-found");
29        } else if (found && !emptyList) {
30            Volume vol = DBUtil.getVolumefromRequest(request);
31            idVol = vol.getVolumeId();
32
33            if (idVol == 1) {
34                System.out.println("Volume id iniziale: " + volumeId);
35                SessionErrors.add(request, "error-volume");
36            } else if (SearchValidator.volumeNotNull(idVol) && !(idVol == 1))
37
38            {
39                System.out.println("Volume id action : " + vol.getVolumeId());
40
41                response.setRenderParameter("volId", volumeIdentifier);
42                System.out.println("search volume clicked");
43
44                PortletPreferences prefs = request.getPreferences();
45                String volumeIdent = request.getParameter("volumeId");
46                if (volumeIdent != null) {
47                    prefs.setValue("volumeIdPref", volumeIdent);
48                    prefs.store();
49                }
50
51                VolumeLocalServiceUtil.clearService();
52
53                SessionMessages.add(request, "search-volume");
54
55            }
56        } else
57            SessionErrors.add(request, "error-volume");
58
59        response.setRenderParameter("jspPage", viewDatabaseJSP);
60
61    }



JSP page:
  1
  2
  3<%@include file="/init.jsp"%>
  4<portlet:defineObjects />
  5
  6<%
  7    CaseArchiveLocalServiceUtil.clearCache();
  8    VolumeLocalServiceUtil.clearCache();
  9
 10    //RoiLocalServiceUtil.clearCache();
 11    //ImageDBLocalServiceUtil.clearCache();
 12    //DicomLocalServiceUtil.clearCache();
 13    ImageTypeLocalServiceUtil.clearCache();
 14
 15    List<Volume> volumes = VolumeLocalServiceUtil.getAllVolumes();
 16    List<CaseArchive> cases = CaseArchiveLocalServiceUtil.getAllCases();
 17    Long volumeIdentifier = 1L;
 18
 19    Collections.sort(volumes, new Comparator<Volume>() {
 20        public int compare(Volume o1, Volume o2) {
 21            Volume p1 = (Volume) o1;
 22            Volume p2 = (Volume) o2;
 23            return p1.getVolumeName().compareToIgnoreCase(
 24                    p2.getVolumeName());
 25        }
 26    });
 27
 28    PortletURL portletURL = renderResponse.createRenderURL();
 29
 30    portletURL.setParameter("jspPage", "/html/admin/viewDatabase.jsp");
 31
 32    int selected = 0;
 33    String volSel = null;
 34
 35    PortletPreferences prefs = renderRequest.getPreferences();
 36    String volumeId = (String) prefs.getValue("volumeIdPref", "1");
 37%>
 38
 39<portlet:renderURL var="backUpURL">
 40    <portlet:param name="jspPage" value="/html/admin/backUp.jsp" />
 41</portlet:renderURL>
 42
 43<portlet:renderURL var="cancelURL">
 44    <portlet:param name="jspPage" value="/html/admin/view.jsp" />
 45</portlet:renderURL>
 46
 47<portlet:actionURL var="searchVolumeURL" name="searchVolume">
 48
 49</portlet:actionURL>
 50
 51<liferay-ui:success key="no-cases-found" message="no-cases" />
 52<liferay-ui:success key="search-volume" message="search-ok" />
 53<liferay-ui:error key="error-volume" message="volume-name-required" />
 54
 55
 56<aui:form name="fm" action="<%=searchVolumeURL.toString()%>"
 57    method="post">
 58    <aui:fieldset>
 59        <aui:select name="volumeId" label="Volume">
 60            <aui:option value="1">
 61                <liferay-ui:message key="Choose volume" />
 62            </aui:option>
 63            <%
 64                for (Volume volume : volumes) {
 65            %>
 66            <aui:option value="<%=volume.getVolumeId()%>">
 67                <%=volume.getVolumeName()%>
 68            </aui:option>
 69            <%
 70                }
 71            %>
 72        </aui:select>
 73
 74        <aui:button-row>
 75            <aui:button type="submit" value="Search" />
 76        </aui:button-row>
 77
 78    </aui:fieldset>
 79</aui:form>
 80
 81<liferay-ui:search-container delta="10" iteratorURL="<%=portletURL%>">
 82
 83    <liferay-ui:search-container-results>
 84        <%
 85            if (request.getParameter("volId") != null) {
 86                        volumeIdentifier = (long) Integer.parseInt(volumeId);
 87                        System.out.println("volId "
 88                                + request.getParameter("volId"));
 89
 90                        System.out.println("volumeId: from pref "
 91                                + volumeIdentifier);
 92
 93                    } else if (searchContainer.getCur() > 1) {
 94                        volumeIdentifier = (long) Integer.parseInt(volumeId);
 95
 96                    }
 97
 98                    List<CaseArchive> tempResults = DBUtil
 99                            .getAllCasesOk(volumeIdentifier);
100
101                    results = ListUtil.subList(tempResults,
102                            searchContainer.getStart(),
103                            searchContainer.getEnd());
104
105                    total = tempResults.size();
106
107                    pageContext.setAttribute("results", results);
108                    pageContext.setAttribute("total", total);
109
110                    portletURL.setParameter("cur",
111                            searchContainer.getCurParam());
112                    System.out.println("Cur PRINT:" + searchContainer.getCur());
113        %>
114
115    </liferay-ui:search-container-results>
116
117    <liferay-ui:search-container-row className="it.dicom.model.CaseArchive"
118        keyProperty="caseId" modelVar="caseArchive">
119
120        <liferay-ui:search-container-column-text name="Case Name"
121            property="caseName" />
122        <liferay-ui:search-container-column-jsp path="/html/admin/backUp.jsp"
123            align="right" />
124        <liferay-ui:search-container-column-button align="right"
125            href="<%=backUpURL%>" name='view Case' />
126
127    </liferay-ui:search-container-row>
128
129    <liferay-ui:search-iterator />
130
131</liferay-ui:search-container>
132
133<p>
134    <br /> <br /> <a href="<%=cancelURL%>">&larr; Back to Menu</a>
135</p>


In the example above, volumeId is the form action parameter (passed by the select option), while volumeIdPref is the portlet preferences parameter, which keeps the value while consulting the pages.
In the action method, that is invoked when submitting the form value, i've set a response parameter called volId which is used in the jsp to set the variable value when invoking the search-container result page "1". The render parameter is null when visiting the other pages, but it can be retrieved by the portlet preferences value.

I hope this helps. Let me know if you have questions or suggestions.
Regards
Laura
Ruchir Chaturvedi
RE: Search container with form parameter - pagination problem SOLVED
9 aprile 2013 9.53
Risposta

Ruchir Chaturvedi

Punteggio: New Member

Messaggi: 1

Data di Iscrizione: 19 luglio 2012

Messaggi recenti

Nice post, Thanks.
Jacques Traore
RE: Search container with form parameter - pagination problem SOLVED
15 maggio 2013 11.17
Risposta

Jacques Traore

Punteggio: Junior Member

Messaggi: 47

Data di Iscrizione: 21 gennaio 2013

Messaggi recenti

Very useful.
Thanks.
vijay pandey
RE: Search container with form parameter - pagination problem SOLVED
15 maggio 2013 23.46
Risposta

vijay pandey

Punteggio: Junior Member

Messaggi: 44

Data di Iscrizione: 1 settembre 2010

Messaggi recenti

informative information show in blog post

Cheers
Vijay Pandey
Scarletake Bwi
RE: Search container with form parameter - pagination problem SOLVED
17 luglio 2013 23.18
Risposta

Scarletake Bwi

Punteggio: Junior Member

Messaggi: 98

Data di Iscrizione: 19 dicembre 2010

Messaggi recenti

thank you.

but after i tried. it doesn't work.

not only "delta", "orderable" doesn't work too.

i just use a jsp file named "view.jsp"
 1
 2<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
 3<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
 4<%@ page import="java.util.List"%>
 5<%@ page import="com.liferay.portal.kernel.util.ListUtil"%>
 6<%@ page import="com.liferay.portal.service.UserLocalServiceUtil"%>
 7<%@ page import="com.liferay.portal.model.User"%>
 8
 9<%@ page import="javax.portlet.PortletURL"%>
10<portlet:defineObjects />
11<liferay-theme:defineObjects />
12<%@ page language="java" contentType="text/html; charset=UTF-8"%>
13<%
14    List<User> userList = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());
15    int count = userList.size();
16    PortletURL portletURL = renderResponse.createRenderURL();
17%>
18<liferay-ui:search-container delta="10"
19    emptyResultsMessage="no-users-were-found" iteratorURL="<%=portletURL%>">
20    <liferay-ui:search-container-results results="<%=userList%>" total="<%=count%>" />
21    <liferay-ui:search-container-row
22        className="com.liferay.portal.model.User" keyProperty="userId"
23        modelVar="user">
24        <liferay-ui:search-container-column-text name="name"
25            value="<%=user.getFullName()%>" />
26        <liferay-ui:search-container-column-text name="first-name"
27            property="firstName" orderable="<%=true%>" orderableProperty="firstName"/>
28    </liferay-ui:search-container-row>
29    <liferay-ui:search-iterator />
30</liferay-ui:search-container>


can anyone please kindly help.
Allegato

Allegati: testpagionation_.png (15,2k)
Amit Doshi
RE: Search container with form parameter - pagination problem SOLVED
18 luglio 2013 1.49
Risposta

Amit Doshi

Punteggio: Liferay Master

Messaggi: 549

Data di Iscrizione: 29 dicembre 2010

Messaggi recenti

Hi All,

Please check this link for search container.

You can also download full source code at the end.

Thanks & Regards,
Amit Doshi
Scarletake Bwi
RE: Search container with form parameter - pagination problem SOLVED
19 luglio 2013 0.37
Risposta

Scarletake Bwi

Punteggio: Junior Member

Messaggi: 98

Data di Iscrizione: 19 dicembre 2010

Messaggi recenti

Amit Doshi:
Hi All,

Please check this link for search container.

You can also download full source code at the end.

Thanks & Regards,
Amit Doshi


Thank you very much, Mr. Amit

your source code really make me understand about it more deep and clear.

but in my situation, i had another problem. I don't know how to keep my result.
like the image i upload

i had a form, and the result is base on the conditions.

so, my first jsp like this..
1
2<portlet:actionURL var="vmiQueryRamindListFunctionURL" name="queryRemindList">
3    <portlet:param name="getListUrl" value="getList" />
4</portlet:actionURL>
5<aui:form id="FORM_ID"
6    action="<%=getListUrl%>" method="post">
7.....


and my portlet
1
2public void getList(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
3        .....
4actionRequest.setAttribute("theList",theList);


in my util
1
2public static void searchContainerData(RenderRequest renderRequest, RenderResponse renderResponse) {...
3                theList= (List<User>) renderRequest.getAttribute(theList);
4                total = theList.size();
5                theList= ListUtil.subList(theList, searchContainer.getStart(), searchContainer.getEnd());
6                searchContainer.setTotal(total);
7                searchContainer.setResults(theList);
8...       



i can use something like service builder, create a table for save userid and what user's conditions.

but i really think it's ain't good way.

any suggestion?
Allegato

Allegati: issue04.png (35,3k)
Amit Doshi
RE: Search container with form parameter - pagination problem SOLVED
19 luglio 2013 1.26
Risposta

Amit Doshi

Punteggio: Liferay Master

Messaggi: 549

Data di Iscrizione: 29 dicembre 2010

Messaggi recenti

Hi Scarletake,

I don't know whether I am able to understand your problem correctly or not.
The situation that I understood is as below:-

You have one Form and on clicking the Query List button, it should return the relevant result of the Data that you passed from the form.
But the Situation is that when you go to the Next and Previous button of the Search Container, your result does not remain intact.

Solution :-

You have to pass your parameter in the Iteratorurl then your problem will get solved.

Let me know if required more details on it.

Hope I understand you correctly.

Thanks & Regards,
Amit Doshi
Scarletake Bwi
RE: Search container with form parameter - pagination problem SOLVED
19 luglio 2013 2.25
Risposta

Scarletake Bwi

Punteggio: Junior Member

Messaggi: 98

Data di Iscrizione: 19 dicembre 2010

Messaggi recenti

Amit Doshi:
Hi Scarletake,

I don't know whether I am able to understand your problem correctly or not.
The situation that I understood is as below:-

You have one Form and on clicking the Query List button, it should return the relevant result of the Data that you passed from the form.
But the Situation is that when you go to the Next and Previous button of the Search Container, your result does not remain intact.

Solution :-

You have to pass your parameter in the Iteratorurl then your problem will get solved.

Let me know if required more details on it.

Hope I understand you correctly.

Thanks & Regards,
Amit Doshi


First, thank you, Mr.Amit

Yes, you're correct.
and the root cause is, I don't know how to keep the list on somewhere(in old day, i will create a hidden some thing in my grid).

can you tell me, how to pass a list object from renderRequest in to iteratorurl?
Amit Doshi
RE: Search container with form parameter - pagination problem SOLVED
22 luglio 2013 0.11
Risposta

Amit Doshi

Punteggio: Liferay Master

Messaggi: 549

Data di Iscrizione: 29 dicembre 2010

Messaggi recenti

Hi Scarletake,

Instead of Iterating the list and doing all sort of things in the jsp page.

Do simple thing, make entire search container from the backend. As you can see in my previous link.

Put list in the Search container. No need to maintain the list. This job will done by the search container depending on the different parameters.

List<UserGroup> userGroupList = ListUtil.subList(userGroupList, searchContainer.getStart(), searchContainer.getEnd());

searchContainer.setTotal(total);
searchContainer.setResults(userGroupList);

renderRequest.setAttribute("userGroupSearchContainer", searchContainer);

Just need to set only one attribute that is container.

Please check the link that I have posted in my previous post. It will give you detail idea.

Thanks & Regards,\
Amit D,.
Scarletake Bwi
RE: Search container with form parameter - pagination problem SOLVED
9 ottobre 2013 4.37
Risposta

Scarletake Bwi

Punteggio: Junior Member

Messaggi: 98

Data di Iscrizione: 19 dicembre 2010

Messaggi recenti

Amit Doshi:
Hi Scarletake,

Instead of Iterating the list and doing all sort of things in the jsp page.

Do simple thing, make entire search container from the backend. As you can see in my previous link.

Put list in the Search container. No need to maintain the list. This job will done by the search container depending on the different parameters.

List<UserGroup> userGroupList = ListUtil.subList(userGroupList, searchContainer.getStart(), searchContainer.getEnd());

searchContainer.setTotal(total);
searchContainer.setResults(userGroupList);

renderRequest.setAttribute("userGroupSearchContainer", searchContainer);

Just need to set only one attribute that is container.

Please check the link that I have posted in my previous post. It will give you detail idea.

Thanks & Regards,\
Amit D,.


Dear Mr. Amit

thank you.

but i had a problem.

my plan is, transform my list to Json Array, than i don't have to query in searchContainer every time user operate( for ex: go next page).

but, my Iteratorurl doesn't work.

 1
 2<%
 3    PortletURL iteratorURL = renderResponse.createActionURL();
 4    iteratorURL.setParameter(Constant.JSON_STR, ParamUtil.getString(renderRequest, Constant.JSON_STR));
 5    System.out.println("in view:"+ParamUtil.getString(renderRequest, Constant.JSON_STR));
 6
 7%>
 8<liferay-ui:search-container
 9        searchContainer="${recordSearchContainer}" iteratorURL="<%=iteratorURL %>">
10.....

i print it out, it had data. but if i try next page or change delta, i got nothing in my doView.

any suggestion?

thank you.
Scarletake Bwi
RE: Search container with form parameter - pagination problem SOLVED
9 ottobre 2013 16.04
Risposta

Scarletake Bwi

Punteggio: Junior Member

Messaggi: 98

Data di Iscrizione: 19 dicembre 2010

Messaggi recenti

SOLVED, THANK YOU.