Aim of this article:
In this article we are demonstrating how quickly we can use Liferay Search Container feature in JSP using Liferay IDE.
A little about Liferay Search Container:
Liferay provides UI Taglib as well as APIs to display data in grid format in a consistent meaner which is commonly known as Liferay Search Container. A grid displayed by Liferay Search Container may have pagination too.
Liferay IDE to generate code:
For beginners it may be difficult to understand Liferay Search Container at the beginning. Even for expert its difficult to remember all the tag syntax as well as its attribute. If your eclipse has Liferay IDE plugin then implementing Liferay Search Container is a matter of few minutes. By using snippets we can easily choose the model class for which we can generate code for Liferay Search Container.
Its assumed that you have Liferay IDE installed in your eclipse as plugin. Bellow are the step by step guide.
Step 1:
Have a look in your Snippets panel in your eclipse. If its missing in your eclipse then you can add it. Follow the screen shot.
The snippets panel look like this
Step 2: Click on Liferay UI Search Container Section. Then double click on Model Search Container. Follow the bellow screen shot.
Step 2:Â You will see the below screen. Click Browse.
Step 3: Type the model class name as in the below screen. In this article we will create a grid of all the users in Liferay. So our model calss is User. You can choose any other model class.
Step 4: After selecting the model class you have to select properties of the model class which will be displayed in the grid. Click Finish button after selecting properties.
 Note1: You have to be ensured where you want the code to be generated. Before doing all the steps just open your JSP and keep your cursor in the JSP where you want code to be inserted.
Note 2: To use Liferay Search Container you should have below import in your JSP. This line wont be generated by Liferay IDE.
 <%@ taglib uri=”http://liferay.com/tld/ui” prefix=”liferay-ui” %>
As soon as you click the Finish button the code will be inserted into the JSP. Below are the code inserted in the JSP.
<liferay-ui:search-container> <liferay-ui:search-container-results results="<%= UserLocalServiceUtil.getUsers(searchContainer.getStart(), searchContainer.getEnd()) %>" total="<%= UserLocalServiceUtil.getUsersCount() %>" /> <liferay-ui:search-container-row className="com.liferay.portal.model.User" modelVar="aUser" > <liferay-ui:search-container-column-text property="birthday" /> <liferay-ui:search-container-column-text property="addresses" /> <liferay-ui:search-container-column-text property="firstName" /> <liferay-ui:search-container-column-text property="fullName" /> <liferay-ui:search-container-column-text property="lastName" /> <liferay-ui:search-container-column-text property="middleName" /> </liferay-ui:search-container-row> <liferay-ui:search-iterator /> </liferay-ui:search-container>
Note: After auto generation of code you may have to resolve import statements. So necessary Util class has to be imported in your JSP. In this example we have used User model class. For example we need to import UserLocalServiceUtil as below
<%@page import=”com.liferay.portal.service.UserLocalServiceUtil”%>
In this article we have shown only how to generate Liferay Search Container Code in our JSP.
currently i am trying to show 50000 data using search container but page is doesn’t loading .
what to do now ??
Hope you are not displaying 50000 data in single page. You should use pagination for that.
Regards
Admin
https://www.proliferay.com
hi sir, am new to liferay i want idea on liferay search container..
Liferay Search Container pagination problem.
Am in 3rd page of liferay search Container. if i delete any record instead of going to 1st page i want to go previous page.. so any suggestion.. Am using Liferay MVC.
Hi Hamidul,
I am getting data json object through restful webservices from salesforce.I can manage all the rows .But the pagination is not working .where default param is given as 5.Eventhough I am getting all the values in the portlet.
Below are the liferay posted url
https://www.liferay.com/community/forums/-/message_boards/message/70616859
Kind Regards,
Hamza
Very good job Hamidul, but, how can i to implement a search form in search container?