留言板

Search container with form parameter - pagination problem SOLVED

thumbnail
Laura Liparulo,修改在11 年前。

Search container with form parameter - pagination problem SOLVED

Junior Member 帖子: 38 加入日期: 12-6-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:

		public void searchVolume(ActionRequest request, ActionResponse response)
			throws IOException, PortletException, PortalException,
			SystemException, NoSuchVolumeException {

		String volumeIdentifier = request.getParameter("volumeId");
		long volumeId = (long) Integer.parseInt(volumeIdentifier);
		long idVol = 0;

		boolean found = false;
		boolean emptyList = false;

		List<volume> volume = new ArrayList<volume>();
		volume = VolumeLocalServiceUtil.getAllVolumes();
		List<casearchive> caseArchive = new ArrayList<casearchive>();
		caseArchive = CaseArchiveLocalServiceUtil
				.getAllCasesbyVolumeId(volumeId);

		if (caseArchive.size() == 0) {
			emptyList = true;
		}

		for (Volume itemVolume : volume) {
			if (itemVolume.getVolumeId() == volumeId)
				found = true;
		}

		if (found &amp;&amp; emptyList) {
			SessionMessages.add(request, "no-cases-found");
		} else if (found &amp;&amp; !emptyList) {
			Volume vol = DBUtil.getVolumefromRequest(request);
			idVol = vol.getVolumeId();

			if (idVol == 1) {
				System.out.println("Volume id iniziale: " + volumeId);
				SessionErrors.add(request, "error-volume");
			} else if (SearchValidator.volumeNotNull(idVol) &amp;&amp; !(idVol == 1))

			{
				System.out.println("Volume id action : " + vol.getVolumeId());

				response.setRenderParameter("volId", volumeIdentifier);
				System.out.println("search volume clicked");

				PortletPreferences prefs = request.getPreferences();
				String volumeIdent = request.getParameter("volumeId");
				if (volumeIdent != null) {
					prefs.setValue("volumeIdPref", volumeIdent);
					prefs.store();
				}

				VolumeLocalServiceUtil.clearService();

				SessionMessages.add(request, "search-volume");

			}
		} else
			SessionErrors.add(request, "error-volume");

		response.setRenderParameter("jspPage", viewDatabaseJSP);

	}
</casearchive></casearchive></volume></volume>



JSP page:


&lt;%@include file="/init.jsp"%&gt;
<portlet:defineobjects />

&lt;%
	CaseArchiveLocalServiceUtil.clearCache();
	VolumeLocalServiceUtil.clearCache();

	//RoiLocalServiceUtil.clearCache();
	//ImageDBLocalServiceUtil.clearCache();
	//DicomLocalServiceUtil.clearCache();
	ImageTypeLocalServiceUtil.clearCache();

	List<volume> volumes = VolumeLocalServiceUtil.getAllVolumes();
	List<casearchive> cases = CaseArchiveLocalServiceUtil.getAllCases();
	Long volumeIdentifier = 1L;

	Collections.sort(volumes, new Comparator<volume>() {
		public int compare(Volume o1, Volume o2) {
			Volume p1 = (Volume) o1;
			Volume p2 = (Volume) o2;
			return p1.getVolumeName().compareToIgnoreCase(
					p2.getVolumeName());
		}
	});

	PortletURL portletURL = renderResponse.createRenderURL();

	portletURL.setParameter("jspPage", "/html/admin/viewDatabase.jsp");

	int selected = 0;
	String volSel = null;

	PortletPreferences prefs = renderRequest.getPreferences();
	String volumeId = (String) prefs.getValue("volumeIdPref", "1");
%&gt;

<portlet:renderurl var="backUpURL">
	<portlet:param name="jspPage" value="/html/admin/backUp.jsp" />
</portlet:renderurl>

<portlet:renderurl var="cancelURL">
	<portlet:param name="jspPage" value="/html/admin/view.jsp" />
</portlet:renderurl>

<portlet:actionurl var="searchVolumeURL" name="searchVolume">

</portlet:actionurl>

<liferay-ui:success key="no-cases-found" message="no-cases" />
<liferay-ui:success key="search-volume" message="search-ok" />
<liferay-ui:error key="error-volume" message="volume-name-required" />


<aui:form name="fm" action="<%=searchVolumeURL.toString()%>" method="post">
	<aui:fieldset>
		<aui:select name="volumeId" label="Volume">
			<aui:option value="1">
				<liferay-ui:message key="Choose volume" />
			</aui:option>
			&lt;%
				for (Volume volume : volumes) {
			%&gt;
			<aui:option value="<%=volume.getVolumeId()%>">
				&lt;%=volume.getVolumeName()%&gt;
			</aui:option>
			&lt;%
				}
			%&gt;
		</aui:select>

		<aui:button-row>
			<aui:button type="submit" value="Search" />
		</aui:button-row>

	</aui:fieldset>
</aui:form>

<liferay-ui:search-container delta="10" iteratorurl="<%=portletURL%>">

	<liferay-ui:search-container-results>
		&lt;%
			if (request.getParameter("volId") != null) {
						volumeIdentifier = (long) Integer.parseInt(volumeId);
						System.out.println("volId "
								+ request.getParameter("volId"));

						System.out.println("volumeId: from pref "
								+ volumeIdentifier);

					} else if (searchContainer.getCur() &gt; 1) {
						volumeIdentifier = (long) Integer.parseInt(volumeId);

					}

					List<casearchive> tempResults = DBUtil
							.getAllCasesOk(volumeIdentifier);

					results = ListUtil.subList(tempResults,
							searchContainer.getStart(),
							searchContainer.getEnd());

					total = tempResults.size();

					pageContext.setAttribute("results", results);
					pageContext.setAttribute("total", total);

					portletURL.setParameter("cur",
							searchContainer.getCurParam());
					System.out.println("Cur PRINT:" + searchContainer.getCur());
		%&gt;

	</casearchive></liferay-ui:search-container-results>

	<liferay-ui:search-container-row classname="it.dicom.model.CaseArchive" keyproperty="caseId" modelvar="caseArchive">

		<liferay-ui:search-container-column-text name="Case Name" property="caseName" />
		<liferay-ui:search-container-column-jsp path="/html/admin/backUp.jsp" align="right" />
		<liferay-ui:search-container-column-button align="right" href="<%=backUpURL%>" name="view Case" />

	</liferay-ui:search-container-row>

	<liferay-ui:search-iterator />

</liferay-ui:search-container>

<p>
	<br> <br> <a href="<%=cancelURL%>">← Back to Menu</a>
</p>
</volume></casearchive></volume>


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,修改在10 年前。

RE: Search container with form parameter - pagination problem SOLVED

New Member 发布: 1 加入日期: 12-7-19 最近的帖子
Nice post, Thanks.
thumbnail
Jacques Traore,修改在10 年前。

RE: Search container with form parameter - pagination problem SOLVED

Junior Member 帖子: 49 加入日期: 13-1-21 最近的帖子
Very useful.
Thanks.
thumbnail
vijay pandey,修改在10 年前。

RE: Search container with form parameter - pagination problem SOLVED

Junior Member 帖子: 44 加入日期: 10-9-1 最近的帖子
informative information show in blog post

Cheers
Vijay Pandey
Scarletake Bwi,修改在3 年前。

RE: Search container with form parameter - pagination problem SOLVED

Expert 帖子: 326 加入日期: 10-12-20 最近的帖子
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"

&lt;%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%&gt;
&lt;%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%&gt;
&lt;%@ page import="java.util.List"%&gt;
&lt;%@ page import="com.liferay.portal.kernel.util.ListUtil"%&gt;
&lt;%@ page import="com.liferay.portal.service.UserLocalServiceUtil"%&gt;
&lt;%@ page import="com.liferay.portal.model.User"%&gt;

&lt;%@ page import="javax.portlet.PortletURL"%&gt;
<portlet:defineobjects />
<liferay-theme:defineobjects />
&lt;%@ page language="java" contentType="text/html; charset=UTF-8"%&gt;
&lt;%
	List<user> userList = UserLocalServiceUtil.getUsers(0, UserLocalServiceUtil.getUsersCount());
	int count = userList.size();
	PortletURL portletURL = renderResponse.createRenderURL();
%&gt;
<liferay-ui:search-container delta="10" emptyresultsmessage="no-users-were-found" iteratorurl="<%=portletURL%>">
	<liferay-ui:search-container-results results="<%=userList%>" total="<%=count%>" />
	<liferay-ui:search-container-row classname="com.liferay.portal.model.User" keyproperty="userId" modelvar="user">
		<liferay-ui:search-container-column-text name="name" value="<%=user.getFullName()%>" />
		<liferay-ui:search-container-column-text name="first-name" property="firstName" orderable="<%=true%>" orderableProperty="firstName" />
	</liferay-ui:search-container-row>
	<liferay-ui:search-iterator />
</liferay-ui:search-container>

</user>


can anyone please kindly help.
thumbnail
Amit Doshi,修改在10 年前。

RE: Search container with form parameter - pagination problem SOLVED

Liferay Master 帖子: 550 加入日期: 10-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,修改在3 年前。

RE: Search container with form parameter - pagination problem SOLVED

Expert 帖子: 326 加入日期: 10-12-20 最近的帖子
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..

<portlet:actionurl var="vmiQueryRamindListFunctionURL" name="queryRemindList">
	<portlet:param name="getListUrl" value="getList" />
</portlet:actionurl>
<aui:form id="FORM_ID" action="<%=getListUrl%>" method="post">
.....
</aui:form>


and my portlet

public void getList(ActionRequest actionRequest, ActionResponse actionResponse) throws PortletException, IOException {
		.....
actionRequest.setAttribute("theList",theList);


in my util

public static void searchContainerData(RenderRequest renderRequest, RenderResponse renderResponse) {...
				theList= (List<user>) renderRequest.getAttribute(theList);
				total = theList.size();
				theList= ListUtil.subList(theList, searchContainer.getStart(), searchContainer.getEnd());
				searchContainer.setTotal(total);
				searchContainer.setResults(theList);
...		
</user>



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?
thumbnail
Amit Doshi,修改在10 年前。

RE: Search container with form parameter - pagination problem SOLVED

Liferay Master 帖子: 550 加入日期: 10-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,修改在3 年前。

RE: Search container with form parameter - pagination problem SOLVED

Expert 帖子: 326 加入日期: 10-12-20 最近的帖子
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?
thumbnail
Amit Doshi,修改在10 年前。

RE: Search container with form parameter - pagination problem SOLVED

Liferay Master 帖子: 550 加入日期: 10-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,修改在3 年前。

RE: Search container with form parameter - pagination problem SOLVED

Expert 帖子: 326 加入日期: 10-12-20 最近的帖子
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.


&lt;%
	PortletURL iteratorURL = renderResponse.createActionURL();
	iteratorURL.setParameter(Constant.JSON_STR, ParamUtil.getString(renderRequest, Constant.JSON_STR));
	System.out.println("in view:"+ParamUtil.getString(renderRequest, Constant.JSON_STR));

%&gt;
<liferay-ui:search-container searchcontainer="${recordSearchContainer}" iteratorurl="<%=iteratorURL %>">
.....
</liferay-ui:search-container>

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,修改在3 年前。

RE: Search container with form parameter - pagination problem SOLVED

Expert 帖子: 326 加入日期: 10-12-20 最近的帖子
SOLVED, THANK YOU.
thumbnail
hamza yusuf,修改在8 年前。

RE: Search container with form parameter - pagination problem SOLVED

New Member 帖子: 2 加入日期: 16-2-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
<portlet:actionurl name="leadAction" var="leadActionURL">
</portlet:actionurl>

<a href="<%= leadActionURL %>">
	<i class="icon-rocket"></i>
	Create Lead
</a>


 &lt;%
 	String keywords = ParamUtil.getString(request, "keywords");
	//PortletURL portletURL = renderResponse.createRenderURL();
	SearchContainer searchContainer = null; 
    String jsonValue=null;
	try{
		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>"));
		searchContainer.getDeltaParam();
		jsonValue=request.getAttribute("jsonValue").toString();
		JSONObject json = new JSONObject(jsonValue);
		JSONArray jsonArray = json.getJSONArray("records");
		List<string> headerNames = new ArrayList<string>();
	    headerNames.add("LEAD FIRST NAME");
	    headerNames.add("LEAD LAST NAME");
	    headerNames.add("LEAD COMPANY");
	    searchContainer.setHeaderNames(headerNames);
		List<string> leadFNameList = new ArrayList<string>();
		List<string> leadLNameList = new ArrayList<string>();
		List<string> leadCmpnyList = new ArrayList<string>();
		for (int i = 0; i &lt; jsonArray.length(); i++){
			 String leadFirstName = json.getJSONArray("records").getJSONObject(i).getString("FirstName");
			 String leadLastName = json.getJSONArray("records").getJSONObject(i).getString("LastName");
			 String leadCompany = json.getJSONArray("records").getJSONObject(i).getString("Company");
			 leadFNameList.add(leadFirstName);
			 leadLNameList.add(leadLastName);
			 leadCmpnyList.add(leadCompany);
		}
		//ResultRow row=null;
		List resultRows = searchContainer.getResultRows();
		int resultRowLength=resultRows.size();
		for(int i=0; i<leadfnamelist.size(); i++){ string leadfname="(String)leadFNameList.get(i);" leadlname="(String)leadLNameList.get(i);" leadcmpny="(String)leadCmpnyList.get(i);" resultrow row="new" resultrow(leadfname, i, i); row.addtext(leadfname); row.addtext(leadlname); row.addtext(leadcmpny); system.out.println("---------row-----------"+row); resultrows.add(i, row); } searchcontainer.setdelta(5); searchcontainer.settotal(leadfnamelist.size()); catch(exception e){ e.printstacktrace(); %> 

<c:if test="${jsonValue != null}">
 <liferay-ui:search-iterator searchContainer="<%= searchContainer %>" paginate="true" /> 
</c:if> </leadfnamelist.size();></string></string></string></string></string></string></string></string>


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

Best Regards,
Hamza Yusuf
Abdur rasheed,修改在8 年前。

RE: Search container with form parameter - pagination problem SOLVED

Junior Member 帖子: 71 加入日期: 08-9-26 最近的帖子
Hi,
Just check your IteratorURl getting properly or not.
Thanks
Abdur
thumbnail
hamza yusuf,修改在8 年前。

RE: Search container with form parameter - pagination problem SOLVED

New Member 帖子: 2 加入日期: 16-2-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..


 SearchContainer searchContainer = null; 
    String jsonValue=null;
	try{
		jsonValue=request.getAttribute("jsonValue").toString();
		if(jsonValue != null){
			JSONObject json = new JSONObject(jsonValue);
			JSONArray jsonArray = json.getJSONArray("records");
			
			String className=SearchContainer.class.getName();
			System.out.println("------className------"+className);
			
			List<string> headerNames = new ArrayList<string>();
		    headerNames.add("LEAD FIRST NAME");
		    headerNames.add("LEAD LAST NAME");
		    headerNames.add("LEAD COMPANY");
		    searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, iteratorURL, headerNames, "there-are-no-events-on-this-day");
                  searchContainer.setHeaderNames(headerNames);
		    searchContainer.setDelta(5);
		   
		   
		    
		    ResultRow row=null;
			List resultRows = searchContainer.getResultRows();
			for (int i = 0; i &lt; jsonArray.length(); i++){
				 String leadFirstName = json.getJSONArray("records").getJSONObject(i).getString("FirstName");
				 String leadLastName = json.getJSONArray("records").getJSONObject(i).getString("LastName");
				 String leadCompany = json.getJSONArray("records").getJSONObject(i).getString("Company");
				
				 row = new ResultRow(i, i, i);
				 row.addText(leadFirstName);
				 row.addText(leadLastName);
				 row.addText(leadCompany);
				 resultRows.add(row);
			}
			searchContainer.setTotal(resultRows.size());
			searchContainer.setResults(resultRows);
		}
		
	}
	catch(Exception e){
		//e.printStackTrace();
	}</string></string>



Kind Regards,
Hamza Yusuf