フォーラム

ホーム » Liferay Portal » English » 3. Development

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Laura Liparulo
Search container with form parameter - pagination problem SOLVED
2013/01/29 7:11
答え

Laura Liparulo

ランク: Junior Member

投稿: 38

参加年月日: 2012/06/30

最近の投稿

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
2013/04/09 9:53
答え

Ruchir Chaturvedi

ランク: New Member

投稿: 1

参加年月日: 2012/07/19

最近の投稿

Nice post, Thanks.
Jacques Traore
RE: Search container with form parameter - pagination problem SOLVED
2013/05/15 11:17
答え

Jacques Traore

ランク: Junior Member

投稿: 47

参加年月日: 2013/01/21

最近の投稿

Very useful.
Thanks.
vijay pandey
RE: Search container with form parameter - pagination problem SOLVED
2013/05/15 23:46
答え

vijay pandey

ランク: Junior Member

投稿: 44

参加年月日: 2010/09/01

最近の投稿

informative information show in blog post

Cheers
Vijay Pandey
Scarletake Bwi
RE: Search container with form parameter - pagination problem SOLVED
2013/07/17 23:18
答え

Scarletake Bwi

ランク: Regular Member

投稿: 113

参加年月日: 2010/12/19

最近の投稿

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.
画像の固定

添付ファイル: testpagionation_.png (15.2k)
Amit Doshi
RE: Search container with form parameter - pagination problem SOLVED
2013/07/18 1:49
答え

Amit Doshi

ランク: Liferay Master

投稿: 549

参加年月日: 2010/12/29

最近の投稿

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
2013/07/19 0:37
答え

Scarletake Bwi

ランク: Regular Member

投稿: 113

参加年月日: 2010/12/19

最近の投稿

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?
画像の固定

添付ファイル: issue04.png (35.3k)
Amit Doshi
RE: Search container with form parameter - pagination problem SOLVED
2013/07/19 1:26
答え

Amit Doshi

ランク: Liferay Master

投稿: 549

参加年月日: 2010/12/29

最近の投稿

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
2013/07/19 2:25
答え

Scarletake Bwi

ランク: Regular Member

投稿: 113

参加年月日: 2010/12/19

最近の投稿

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
2013/07/22 0:11
答え

Amit Doshi

ランク: Liferay Master

投稿: 549

参加年月日: 2010/12/29

最近の投稿

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
2013/10/09 4:37
答え

Scarletake Bwi

ランク: Regular Member

投稿: 113

参加年月日: 2010/12/19

最近の投稿

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
2013/10/09 16:04
答え

Scarletake Bwi

ランク: Regular Member

投稿: 113

参加年月日: 2010/12/19

最近の投稿

SOLVED, THANK YOU.
hamza yusuf
RE: Search container with form parameter - pagination problem SOLVED
2016/02/22 1:19
答え

hamza yusuf

ランク: New Member

投稿: 2

参加年月日: 2016/02/22

最近の投稿

Scarletake Bwi:
SOLVED, THANK YOU.



Hi Folks,

I can achieve search container using objects.But I facing issue in the pagination part.Where I cant able to view the value based on the delta param value .Instead of that I m getting the whole list value in the order.

I
 1<portlet:actionURL name="leadAction" var="leadActionURL" >
 2</portlet:actionURL>
 3
 4<a href="<%= leadActionURL %>">
 5    <i class="icon-rocket"></i>
 6    Create Lead
 7</a>
 8
 9
10 <%
11     String keywords = ParamUtil.getString(request, "keywords");
12    //PortletURL portletURL = renderResponse.createRenderURL();
13    SearchContainer searchContainer = null;
14    String jsonValue=null;
15    try{
16        searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, portletURL, null, LanguageUtil.format(pageContext, "no-results-were-found-that-matched-the-keywords-x", "<b>" + HtmlUtil.escape(keywords) + "</b>"));
17        searchContainer.getDeltaParam();
18        jsonValue=request.getAttribute("jsonValue").toString();
19        JSONObject json = new JSONObject(jsonValue);
20        JSONArray jsonArray = json.getJSONArray("records");
21        List<String> headerNames = new ArrayList<String>();
22        headerNames.add("LEAD FIRST NAME");
23        headerNames.add("LEAD LAST NAME");
24        headerNames.add("LEAD COMPANY");
25        searchContainer.setHeaderNames(headerNames);
26        List<String> leadFNameList = new ArrayList<String>();
27        List<String> leadLNameList = new ArrayList<String>();
28        List<String> leadCmpnyList = new ArrayList<String>();
29        for (int i = 0; i < jsonArray.length(); i++){
30             String leadFirstName = json.getJSONArray("records").getJSONObject(i).getString("FirstName");
31             String leadLastName = json.getJSONArray("records").getJSONObject(i).getString("LastName");
32             String leadCompany = json.getJSONArray("records").getJSONObject(i).getString("Company");
33             leadFNameList.add(leadFirstName);
34             leadLNameList.add(leadLastName);
35             leadCmpnyList.add(leadCompany);
36        }
37        //ResultRow row=null;
38        List resultRows = searchContainer.getResultRows();
39        int resultRowLength=resultRows.size();
40        for(int i=0; i<leadFNameList.size(); i++){
41            String leadFName = (String)leadFNameList.get(i);
42            String leadLName = (String)leadLNameList.get(i);
43            String leadCmpny = (String)leadCmpnyList.get(i);
44            ResultRow row = new ResultRow(leadFName, i, i);
45            row.addText(leadFName);
46            row.addText(leadLName);
47            row.addText(leadCmpny);
48            System.out.println("---------row-----------"+row);
49            resultRows.add(i, row);
50        }
51        searchContainer.setDelta(5);
52        searchContainer.setTotal(leadFNameList.size());
53               
54    }
55    catch(Exception e){
56        e.printStackTrace();
57    }
58   
59%>
60
61<c:if test="${jsonValue != null}" >
62 <liferay-ui:search-iterator   searchContainer="<%= searchContainer %>"  paginate="true"   />
63</c:if>


I need to sort these issue to display properly.So Folks help me on this ..

Best Regards,
Hamza Yusuf
Abdur rasheed
RE: Search container with form parameter - pagination problem SOLVED
2016/02/23 2:07
答え

Abdur rasheed

ランク: Junior Member

投稿: 71

参加年月日: 2008/09/25

最近の投稿

Hi,
Just check your IteratorURl getting properly or not.
Thanks
Abdur
hamza yusuf
RE: Search container with form parameter - pagination problem SOLVED
2016/02/29 4:07
答え

hamza yusuf

ランク: New Member

投稿: 2

参加年月日: 2016/02/22

最近の投稿

Abdur rasheed:
Hi,
Just check your IteratorURl getting properly or not.
Thanks
Abdur



Dear Folk,

Thanks for your reply dude..I getting the search container properly.
But my issues result row is displaying all the values from the list results value.

These are the below code snippet .I m using in my project .I guess I mess out something in the code.Point out where I m doing mistake in the code.So Folks give me help me on this..


 1 SearchContainer searchContainer = null;
 2    String jsonValue=null;
 3    try{
 4        jsonValue=request.getAttribute("jsonValue").toString();
 5        if(jsonValue != null){
 6            JSONObject json = new JSONObject(jsonValue);
 7            JSONArray jsonArray = json.getJSONArray("records");
 8            
 9            String className=SearchContainer.class.getName();
10            System.out.println("------className------"+className);
11            
12            List<String> headerNames = new ArrayList<String>();
13            headerNames.add("LEAD FIRST NAME");
14            headerNames.add("LEAD LAST NAME");
15            headerNames.add("LEAD COMPANY");
16            searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, iteratorURL, headerNames, "there-are-no-events-on-this-day");
17                  searchContainer.setHeaderNames(headerNames);
18            searchContainer.setDelta(5);
19          
20          
21            
22            ResultRow row=null;
23            List resultRows = searchContainer.getResultRows();
24            for (int i = 0; i < jsonArray.length(); i++){
25                 String leadFirstName = json.getJSONArray("records").getJSONObject(i).getString("FirstName");
26                 String leadLastName = json.getJSONArray("records").getJSONObject(i).getString("LastName");
27                 String leadCompany = json.getJSONArray("records").getJSONObject(i).getString("Company");
28               
29                 row = new ResultRow(i, i, i);
30                 row.addText(leadFirstName);
31                 row.addText(leadLastName);
32                 row.addText(leadCompany);
33                 resultRows.add(row);
34            }
35            searchContainer.setTotal(resultRows.size());
36            searchContainer.setResults(resultRows);
37        }
38       
39    }
40    catch(Exception e){
41        //e.printStackTrace();
42    }



Kind Regards,
Hamza Yusuf