Saturday, September 23, 2017

Liferay Search Form with Search Container


We already know how to use Search Container in Liferay. Today we will create a search form that can search values from search container. For this we use <liferay-ui:search-form> tag. By using this we can apply basic as well as advance search.

Liferay use this in many places like when you go to web content section (Admin->Content)




Here you can search web content by name and when you click Gear icon you can search by id, name etc. You can also apply All(AND) and ANY(OR) operations.

I already created my Services using Service Builder. Here is my service.xml:-



I fill some data in Database:-



Today we apply Searching on these records on the basis of eId and eName.





Project Structure




So lets start this Step by Step:-

Step 1:-Create init.jsp
First we create a init.jsp that contain all the imports:-

init.jsp


Now as you can see in init.jsp we use two java classes EmployeeSearchContainer and EmployeeDisplayTerms. Now we create these two classes.

Step 2:-Create EmployeeSearchContainer.java
Now we create EmployeeSearchContainer that extends SearchContainer in this class we can set properties like empty result message and default records per page(DELTA).

EmployeeSearchContainer.java


Step 3:-Create EmployeeDisplayTerms.java
This class extends DisplayTerms .We want searching on the basis of eId and eName so we create getter and setter for both. This class also gives us important methods like isAdvancedSearch() ,  isAndOperator() etc.

EmployeeDisplayTerms.java
 
 

Step 4:-Create view.jsp
We already discuss about Search container in Liferay. Here we apply searching in this:-

view.jsp


Explanation:-
In this we use liferay-ui:search-form tag that include search.jsp which contain two fields eId and eName:-

search.jsp



Step 5:-Create Helper Class
In view.jsp we use EmployeeHelper class to load the data.In EmployeeHelper we use dynamic query  and Conjunction , Disjunction on the basis of various scenarios like For Normal Search we use Keywords ,for Advance Search ALL operation we use Conjunction , for Advance Search ANY operation we use Disjunction etc.

EmployeeHelper.java


Now Deploy the portlet and check the output




Output:-

1)Normal Search



2)Advance Search



You can download the source code from here.

In the next blog we create Search Form With Search Container but in a simple way.

Hope this will Help....

Related Post:-

No comments:

Post a Comment

Total Pageviews

Number Of Unique Visitor

Free counters!