Message Boards

Explain about search container in liferay 7 ?

lokesh gorrela, modified 7 Years ago.

Explain about search container in liferay 7 ?

Regular Member Posts: 173 Join Date: 3/9/16 Recent Posts
Hi guys,

Anyone knows about search container in liferay7, Please explain with one example.

Thanks
With Regards
Lokesh
thumbnail
Jaydip Lakhatariya, modified 7 Years ago.

RE: Explain about search container in liferay 7 ?

Junior Member Posts: 53 Join Date: 4/18/13 Recent Posts
Hi,

There is not much differences in search container taglib of 6.2 and 7. You can use the same way as were used to do in 6.2. Below is the sample snippets for your reference.

<liferay-ui:search-container delta="5" emptyresultsmessage="No records available" iteratorurl="<%=iteratorURL%>">
	<liferay-ui:search-container-results results="<%= ListUtil.subList(studentList, searchContainer.getStart(), searchContainer.getEnd()) %>" />
	<liferay-ui:search-container-row classname="com.test.Student" keyproperty="studentId" modelvar="student">
       <liferay-ui:search-container-column-text name="Name" value="${student.name}" />
        <liferay-ui:search-container-column-text name="Class" value="${student.class}" />
        <liferay-ui:search-container-column-text name="Grade" value="${student.grade}" />
    </liferay-ui:search-container-row>
    <liferay-ui:search-iterator />
</liferay-ui:search-container>


Hope this helps !

Regards,
Jaydip
lokesh gorrela, modified 7 Years ago.

RE: Explain about search container in liferay 7 ?

Regular Member Posts: 173 Join Date: 3/9/16 Recent Posts
Hello Jaydip Lakhatariya,

In liferay 7 search container using below tags:
<liferay-ui:search-container
id="<%= searchContainerId %>"
rowChecker="<%= siteChecker %>"
searchContainer="<%= groupSearch %>"
>
<liferay-ui:search-container-row
className="com.liferay.portal.kernel.model.Group"
escapedModel="<%= true %>"
keyProperty="groupId"
modelVar="sitegroup"
rowIdProperty="friendlyURL"
rowVar="row"
>
<liferay-ui:search-container-column-text
colspan="<%= 2 %>"
>
</liferay-ui:search-container-column-text>
</liferay-ui:search-container-row>
</liferay-ui:search-container
>

how to use same tags in my portlet and how to get attribute values ?
thumbnail
Jaydip Lakhatariya, modified 7 Years ago.

RE: Explain about search container in liferay 7 ?

Junior Member Posts: 53 Join Date: 4/18/13 Recent Posts
Hi,

In LIFERAY 7 as well use the same tags whichever you want to use. I don't think there is any difference in 7. I have already used search container on one of the sample module which I have developed. Below is the snippets:

Here is my controller code:

SearchContainer<student> searchContainer = null;
searchContainer = new SearchContainer<student>(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, iteratorURL, null, StringPool.BLANK);
searchContainer.setEmptyResultsMessage("No Data Found");		
searchContainer.setResults(ListUtil.subList(students, searchContainer.getStart(), searchContainer.getEnd()));				searchContainer.setTotal(StudentLocalServiceUtil.getStudentsCount());
renderRequest.setAttribute("studentSearchContainer", searchContainer);
</student></student>


JSP code:
<liferay-ui:search-container searchcontainer="${studentSearchContainer}">
<liferay-ui:search-container-results results="${studentSearchContainer.getResults() }" />	
<liferay-ui:search-container-row classname="com.test.student.model.Student" keyproperty="studentName" modelvar="student">
<liferay-ui:search-container-column-text name="studentName" />
<liferay-ui:search-container-column-text name="mark1" />	
</liferay-ui:search-container-row>	
<liferay-ui:search-iterator />
</liferay-ui:search-container>


Regards,
Jaydip
lokesh gorrela, modified 7 Years ago.

RE: Explain about search container in liferay 7 ?

Regular Member Posts: 173 Join Date: 3/9/16 Recent Posts
Hello Jaydip Lakhatariya
Thanks for your replay.

<liferay-ui:search-container-row
className="com.test.student.model.Student"
keyProperty="studentName"
modelVar="student">

Here modelVar="student" attribute is used in above tag. How to get that value, Can you explain it.
thumbnail
Jaydip Lakhatariya, modified 7 Years ago.

RE: Explain about search container in liferay 7 ?

Junior Member Posts: 53 Join Date: 4/18/13 Recent Posts
Hi,

We can say simple local variable as "student" which has define in modelVar="student". You can define any variable here and which will be accessible to get the value from student modal. In your search container if you want to fetch any information from the student model then you can directly use this variable like $student.name or <%= student.getName() %>.

Hence you don't need to get such a object. Just give any name of variable here and you can able to access model information through that variable.

Regards,
Jaydip
lokesh gorrela, modified 7 Years ago.

RE: Explain about search container in liferay 7 ?

Regular Member Posts: 173 Join Date: 3/9/16 Recent Posts
Hello Jaydip Lakhatariya,

Your example code working fine, but pagination is not working. Can you tell the solution for pagination problem in search container. If you possible , plz provide total code.

Thanks
With Regards
Lokesh
thumbnail
Jaydip Lakhatariya, modified 7 Years ago.

RE: Explain about search container in liferay 7 ?

Junior Member Posts: 53 Join Date: 4/18/13 Recent Posts
Hi,

What issues you are facing with the pagination ? Actually pagination is out of the box in search container. In my previous given code below lines are there which are responsible to display only some of the records based on the pagination.

5searchContainer.setResults(ListUtil.subList(students, searchContainer.getStart(), searchContainer.getEnd())); searchContainer.setTotal(StudentLocalServiceUtil.getStudentsCount());

Please try to understand the given code and implement the same. Let me know if you are facing with any issues.

Regards,
Jaydip
thumbnail
Devang Patel, modified 7 Years ago.

RE: Explain about search container in liferay 7 ?

Regular Member Posts: 247 Join Date: 1/19/15 Recent Posts
Hi Lokesh,

Try this :
For Pagination you need to provide the iterator url or <liferay-ui:search-iterator /> tag

1. create renderUrl in controller :
 PortletURL iteratorURL = renderResponse.createRenderURL();
	SearchContainer<bookmarksentry> searchContainer = new SearchContainer<bookmarksentry>(request, null, null, "cur_", DELTA,                 iteratorURL,null, "you-do-not-have-any-bookmarked-posts");</bookmarksentry></bookmarksentry>


In Jsp :
&lt;% PortletURL iteratorURL = renderResponse.createRenderURL(); %&gt;
	<liferay-ui:search-container delta="2" emptyresultsmessage="no such user" iteratorurl="<%=iteratorURL%>"></liferay-ui:search-container>


3. Add the <liferay-ui:search-iterator /> tag in Jsp
thumbnail
Enrique Valdes Lacasa, modified 3 Years ago.

RE: Explain about search container in liferay 7 ?

Junior Member Posts: 92 Join Date: 7/29/14 Recent Posts
Instead of having :

searchContainer.setResults(ListUtil.subList(students, searchContainer.getStart(), searchContainer.getEnd()))


You should sublist the results beforehand, getting the start and end from the searchContainer itself.
Here is a piece of code as an example:

​​​​​​​int numRecords = _XLocalService.getXCount();
int start = searchContainer.getStart();
int end = searchContainer.getEnd();
if (end &gt; numRecords) {
&nbsp;&nbsp;&nbsp;end = numRecords;
}
List<x> records = _XLocalService
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.findByGroupAndInstance(themeDisplay.getScopeGroupId(),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;themeDisplay.getCompanyId(),
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;null,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;null,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;start,
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end);
searchContainer.setResults(records);
searchContainer.setTotal(numRecords);</x>
Gopal Prasad Satapathy, modified 3 Years ago.

RE: Explain about search container in liferay 7 ?

Junior Member Posts: 51 Join Date: 3/29/18 Recent Posts
Any idea how i can filter the search result in the jsp?i am writing something like below. But it is not working.
​​​​​​​List<Document> documents=searchResultsPortletDisplayContext.getDocuments();
List<Document> filteredDocuments = documents.stream()
                                .filter(doc -> !(doc.hasField("extension")&& doc.getField("extension").getValue().matches("jpg|jpeg|png")))
                                .collect(Collectors.toList());
searchResultsPortletDisplayContext.setDocuments(filteredDocuments);