Site icon Pro Liferay

Liferay Search Container by Liferay IDE

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.

Add Snippets

 

The snippets panel look like this

 

Snippets

 

Step 2: Click on Liferay UI Search Container Section. Then double click on Model Search Container. Follow the bellow screen shot.

Model Search Container

 

Step 2:  You will see the below screen. Click Browse.

 

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.

 

Select Model

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.

 

Select Property

 

 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.

Exit mobile version