Foros de discusión

Search Container doesn't display second page

thumbnail
Renata Willi, modificado hace 10 años.

Search Container doesn't display second page

Junior Member Mensajes: 30 Fecha de incorporación: 15/02/13 Mensajes recientes
Hi everybody,

I've got a little problem with the pagination of my search container.
I want to implement an addressbook search portlet. This means a user can enter a name of another user in a search field and the result of the search is displayed in a search container. Sometimes there are more than 30 results, so the search container displays them on e.g. two pages. So far there is no problem, but if I click on the next button of the search container, it forgets the search request and doesn't diplay the second page of the former request.

My implementation is as follows - first the simple search form in my view.jsp:


<form action="<%= getSearchResultURL.toString() %>" method="post" name="fm">
	<input type="text" name="AddressbookSearchRequest" value="<%= (searchRequest == &quot;&quot; || searchRequest == null) ? &quot;&quot; : searchRequest%>">
	<input type="submit">
</form>


If I click on the submit button the java method getSearchResult() just takes the value of the "AddressbookSearchRequest" and sets it in a render parameter "searchRequest":


public void getSearchResult(ActionRequest request, ActionResponse response){
	String searchRequest = ParamUtil.getString(request, "AddressbookSearchRequest");
	response.setRenderParameter("searchRequest", searchRequest);
}


Now the entered searchRequest remains in the search field of the form. And my searchContainer is looking for the results depending on the value of the searchRequest:


<!-- Search for the contacts which matches the "searchRequest"-->
<liferay-ui:search-container-results results="<%= MyAccountLocalServiceUtil.getContacts(searchRequest, searchContainer.getStart(), searchContainer.getEnd()) %>" total="<%= MyAccountLocalServiceUtil.getResultSize() %>" />


I know what the problem is... If I click on the next button the page is rerendered, but as the submit button wasn't clicked, the renderParameter of the searchRequest is null, so the searchcontainer has nothing to look for.

How can I solve this problem. Should I try to use Portlet Preferences? I hope somebody can help me to find a solution.

I'm looking forward to your answers, thanks in advance
thumbnail
Vilmos Papp, modificado hace 10 años.

RE: Search Container doesn't display second page

Liferay Master Mensajes: 529 Fecha de incorporación: 21/10/10 Mensajes recientes
Hi,

I think, the keyword you are searching is pageContext where you can propagate your data. But to be sure, just check out our sample searchcontainer portlet: https://github.com/liferay/liferay-plugins/blob/master/portlets/sample-ui-search-container-taglib-portlet/docroot/advanced.jsp

Regards,
Vilmos
thumbnail
Renata Willi, modificado hace 10 años.

RE: Search Container doesn't display second page

Junior Member Mensajes: 30 Fecha de incorporación: 15/02/13 Mensajes recientes
Thanks, Vilmos, for the example and the keyword.... I'll give it a try....
thumbnail
Renata Willi, modificado hace 10 años.

RE: Search Container doesn't display second page

Junior Member Mensajes: 30 Fecha de incorporación: 15/02/13 Mensajes recientes
Hi Vilmos,

I'm sorry, I don't got it right... I'm missing something... Do I just have to add the two lines with the setting of the pageContext attributes in the <liferay-ui:search-container-results>-tag? And by clicking the next button in the searchContainer, it will take these attributes?


<!-- Search for the contacts which matches the "searchRequest"-->
<liferay-ui:search-container-results>
	&lt;% 
        results = MPIBAccountLocalServiceUtil.getContacts(searchRequest, searchContainer.getStart(), searchContainer.getEnd());
	total = MPIBAccountLocalServiceUtil.getResultSize();
			
	pageContext.setAttribute("results", results);
	pageContext.setAttribute("total", total);
			
	%&gt;
</liferay-ui:search-container-results>	


But this is not working right, the problem still remains, that if I click on the next button of the search container, it looses the searchRequest and displays no results. Or do I have to store the value of the searchRequest variable in a contextPage attribute and call the getContacts()-method with this attribute?

Thanks for your help
thumbnail
Vilmos Papp, modificado hace 10 años.

RE: Search Container doesn't display second page

Liferay Master Mensajes: 529 Fecha de incorporación: 21/10/10 Mensajes recientes
Hi Renata,

I should dig in deeper as it was a few months ago I used search container in my personal projects, so it would take me a while to catch up with it. If you upload a sample project code here that doesn't work perhaps me or someone else can analyze it faster to see what's wrong.

One more thing: I found that Liferay In Action's sample chapter writes about Search Container, so you can read it perhaps it helps you understand the structure/working of it:
http://www.manning.com/sezov/LiA_SampleChapter-04.pdf

Cheers,
Vilmos
thumbnail
Jeffrey Handa, modificado hace 10 años.

RE: Search Container doesn't display second page

Liferay Master Mensajes: 541 Fecha de incorporación: 1/12/08 Mensajes recientes
Hi Renata,

Have you provided a iteratorURL attribute to your liferay-ui:search-container element? Not including the iteratorURL is a common mistake that would cause the issues your seeing.

Regards,
Jeff
thumbnail
Renata Willi, modificado hace 10 años.

RE: Search Container doesn't display second page

Junior Member Mensajes: 30 Fecha de incorporación: 15/02/13 Mensajes recientes
Hi,

thanks both of your for your answers.
I'll read this chapter of search containers.... and I'll try out the interatorURL. That's maybe the problem, because I don't provide an iteratorURL, I just have at the end of my search-container the search-iterator. But that's not exactly the same, I'm right?

My structure is as follows:

<liferay-ui:search-container delta="30" emptyresultsmessage="no-contacts-found">

		<!-- Search for the contacts which matches the "searchRequest"-->
		<liferay-ui:search-container-results>
			&lt;% 
			results = MyAccountLocalServiceUtil.getContacts(searchRequest, searchContainer.getStart(), searchContainer.getEnd());
			total = MyAccountLocalServiceUtil.getResultSize();
			
			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
			
			%&gt;
		</liferay-ui:search-container-results>	
			

		<liferay-ui:search-container-row classname="com.something.model.MyAccount" keyproperty="cn" modelvar="MyAccount" escapedmodel="<%= true %>">
		
			
			<liferay-ui:search-container-column-text name="Name" value="<%=MyAccount.getName() %>" />
			
			..... more column-texts
			
		</liferay-ui:search-container-row>
		<liferay-ui:search-iterator />
	</liferay-ui:search-container>


Regards, Renata
thumbnail
Renata Willi, modificado hace 10 años.

RE: Search Container doesn't display second page

Junior Member Mensajes: 30 Fecha de incorporación: 15/02/13 Mensajes recientes
Hi everybody,

I tried it with the iterator URL... but I don't get it working correctly. The searchRequest the user entered and which is displayed on the first page of the search-container is again null, if I hit the next-Button of the search container.

My code is now as follows:
&lt;%String searchRequest = (String)renderRequest.getParameter("searchRequest");%&gt;

&lt;%
	PortletURL iteratorURL = renderResponse.createRenderURL();
	iteratorURL.setParameter("mvcPath", "/html/AddressbookResults/view.jsp");
%&gt;

<portlet:actionurl name="getSearchResult" var="getSearchResultForAddressbookURL" />


<form action="<%= getSearchResultForAddressbookURL.toString() %>" method="post" id="searchRequestForm" name="searchRequestForm">
	<label id="AddressbookLabel">Search in Addressbook:</label>
	<input type="text" name="searchRequest" id="searchRequest" placeholder="Enter a collegue's name" value="<%= (searchRequest == &quot;&quot; || searchRequest == null) ? &quot;&quot; : searchRequest%>">
	<input type="submit" name="search" id="search" value="Search">
</form>

<!-- SearchContainer displays the contacts of the request. -->
<!-- 1.Case: no searchRequest -->
&lt;% if((searchRequest == null || searchRequest == "") ) {%&gt;
	<p class="no-search-message">no-search</p>

<!-- 2.case: the user is searching for a colleague in the addressbook -->
&lt;%} else if (searchRequest != null &amp;&amp; searchRequest != "") {%&gt;

	<!-- List of Contacts -->
	<liferay-ui:search-container delta="<%= 30 %>" emptyresultsmessage="no-contacts-found" iteratorurl="<%= iteratorURL %>">

		<!-- Search for the contacts which matches the "searchRequest"-->
		<liferay-ui:search-container-results>
			&lt;% 
			results = MyAccountLocalServiceUtil.getContacts(searchRequest, searchContainer.getStart(), searchContainer.getEnd());
			total = MyAccountLocalServiceUtil.getResultSize();
			
			pageContext.setAttribute("results", results);
			pageContext.setAttribute("total", total);
			%&gt;
		</liferay-ui:search-container-results>	

	
		<!-- Create the rows to display the search results -->
		<liferay-ui:search-container-row classname="com.something.model.MyAccount" keyproperty="cn" modelvar="MyAccount" escapedmodel="<%= true %>">
	
			<liferay-ui:search-container-column-text name="Name" value="<%=MyAccount.getFullName() %>" />
			
... more column texts....
			
		</liferay-ui:search-container-row>
		<liferay-ui:search-iterator />
	</liferay-ui:search-container>
&lt;%} %&gt;



I don't know what to do. Can you please help me, I would be so happy, if we get it working emoticon

Thanks in advance
thumbnail
Vilmos Papp, modificado hace 10 años.

RE: Search Container doesn't display second page

Liferay Master Mensajes: 529 Fecha de incorporación: 21/10/10 Mensajes recientes
Can you upload a sample portlet so we can test it? Did you manage to check out the sample portlet I've linked?
thumbnail
Renata Willi, modificado hace 10 años.

RE: Search Container doesn't display second page

Junior Member Mensajes: 30 Fecha de incorporación: 15/02/13 Mensajes recientes
Hi everybody,

thanks for all your answers and samples. With your help I found a solution to my problem just right before my holidays. I will post my solution with sample code soon...
thumbnail
Vilmos Papp, modificado hace 10 años.

RE: Search Container doesn't display second page

Liferay Master Mensajes: 529 Fecha de incorporación: 21/10/10 Mensajes recientes
Hi Renata,

Have a great holiday! Please keep this thread updated with your solution.

Regards,
Vilmos
thumbnail
Renata Willi, modificado hace 9 años.

RE: Search Container doesn't display second page

Junior Member Mensajes: 30 Fecha de incorporación: 15/02/13 Mensajes recientes
Hi everybody,

Our goal was the implementation of a search in an address book. The results should be displayed in a search container

Problem: When I entered a searchRequest in a form (kind of a filter) and hit enter, the search container displayed the first page of the list of entries, which matched the searchRequest, correctly. But every time I clicked 'Next' in the search container, the page was re-rendered and the search container forgot the searchRequest and displayed the whole address list.

Solution: set the searchRequest as parameter in the iteratorURL and get the searchRequest out of the request, when the page is re-rendered.

Example:
Get the searchRequest out of the request:
String searchRequest = ParamUtil.getString(request, "searchRequest");


The iteratorURL of the searchContainer. It's called every time, when you click on a link in the search container, e.g. 'Next'
PortletURL iteratorURL = renderResponse.createRenderURL();
iteratorURL.setParameter("mvcPath","/html/AddressbookResults/view.jsp");
iteratorURL.setParameter("searchRequest", searchRequest);


The ActionURL, which is called when the searchRequest was entered and submitted
<portlet:actionurlname="getsearchresult"var="getsearchresulturl" />


The form, where I enter the searchRequest, e.g. the name of the person I want to find in the address book.
<form action="<%= getSearchResultURL.toString() %>" method="post" name="fm">
     <input type="text" name="AddressbookSearchRequest" value="<%= (searchRequest == &quot;&quot; ) ? &quot;&quot; : searchRequest%>">
     <input type="submit">
</form>


The method, which is called in the .java Class Controller after submitting the searchRequest.
public void getSearchResult(ActionRequest request, ActionResponse response){
     String searchRequest = ParamUtil.getString(request, "AddressbookSearchRequest");
     response.setRenderParameter("searchRequest", searchRequest);
}


The search container, which displays the list of results depending on the searchRequest

<liferay-ui:search-container emptyresultsmessage="No contacts found" iteratorurl="<%=iteratorURL%>" <liferay-ui:search-container-results>
          &lt;%
            List<account> contactsList = AccountLocalServiceUtil.getContacts(searchRequest); 
            total = contactsList.size();
            results = ListUtil.getFromTill(contactsList, searchContainer.getStart(), searchContainer.getEnd(), total);
            pageContext.setAttribute("results", results);
            pageContext.setAttribute("total", total);
          %&gt;
     

     &lt;%-- Columns of the search container --%&gt;
     <liferay-ui:search-iterator />
</account></liferay-ui:search-container>


The ListUtil.java class
public class ListUtil{
     public static List<account> getFromTill(List<account> accountEntries, int from, int till, int totalResultSize) {
          if (till&gt;totalResultSize) {
               till = totalResultSize;
          }
          List<account> result = new ArrayList<account>();
          if (accountEntries.size() &gt; 0) {
               for (int i = from; i &lt; till; i++) {
                    result.add(accountEntries.get(i));
               }
          }
          return result;
     }
}
</account></account></account></account>


I think that's it. I hope I didn't forgot anything...

Cheers,
Renata

P.S. I'm so sorry, that it took me so long to answer this post. I totally forgot. Sorry Sorry Sorry.
thumbnail
Amit Doshi, modificado hace 10 años.

RE: Search Container doesn't display second page

Liferay Master Mensajes: 550 Fecha de incorporación: 29/12/10 Mensajes recientes
Hi Renata Willi ,

I already have a demo on my blog.

Download the complete source code at the end of the blog.

http://liferaytrends.blogspot.in/2013/01/tabs-with-search-container-in-liferay.html

Let me know if any questions.

Thanks & Regards,
Amit Doshi
Stephen Dunkley, modificado hace 8 años.

Automatic reply: [Liferay Forums][3. Development] Hi everybody,

New Member Mensajes: 10 Fecha de incorporación: 13/10/11 Mensajes recientes
I am currently out of the office until Monday, 15th July 2013. If your query is urgent, please contact the helpdesk on x4321
This e-mail may contain information which is confidential, legally privileged and/or copyright protected. This e- mail is intended for the addressee only. If you receive this in error, please contact the sender and delete the material from your computer.
Stephen Dunkley, modificado hace 8 años.

Automatic reply: [Liferay Forums][3. Development] Hi everybody,

New Member Mensajes: 10 Fecha de incorporación: 13/10/11 Mensajes recientes
I am currently out of the office until Monday, 15th July 2013. If your query is urgent, please contact the helpdesk on x4321
This e-mail may contain information which is confidential, legally privileged and/or copyright protected. This e- mail is intended for the addressee only. If you receive this in error, please contact the sender and delete the material from your computer.
Stephen Dunkley, modificado hace 8 años.

Automatic reply: [Liferay Forums][3. Development] Hi everybody,

New Member Mensajes: 10 Fecha de incorporación: 13/10/11 Mensajes recientes
I am currently out of the office until Monday, 15th July 2013. If your query is urgent, please contact the helpdesk on x4321
This e-mail may contain information which is confidential, legally privileged and/or copyright protected. This e- mail is intended for the addressee only. If you receive this in error, please contact the sender and delete the material from your computer.
Stephen Dunkley, modificado hace 8 años.

Automatic reply: [Liferay Forums][3. Development] Hi everybody,

New Member Mensajes: 10 Fecha de incorporación: 13/10/11 Mensajes recientes
I am currently out of the office until Monday, 15th July 2013. If your query is urgent, please contact the helpdesk on x4321
This e-mail may contain information which is confidential, legally privileged and/or copyright protected. This e- mail is intended for the addressee only. If you receive this in error, please contact the sender and delete the material from your computer.
Stephen Dunkley, modificado hace 8 años.

Automatic reply: [Liferay Forums][3. Development] Hi everybody,

New Member Mensajes: 10 Fecha de incorporación: 13/10/11 Mensajes recientes
I am currently out of the office until Monday, 15th July 2013. If your query is urgent, please contact the helpdesk on x4321
This e-mail may contain information which is confidential, legally privileged and/or copyright protected. This e- mail is intended for the addressee only. If you receive this in error, please contact the sender and delete the material from your computer.