Liferay Provide a simple and easy way to show list of Objects in proper tabular format with pagination by using Search Container tag of liferay.
Our goal is to show a list of Student in which:-
1)Column show student name,last name,Class etc.
2)In one column we show address of Student that comes from another jsp.
3)In one column we provide a link .When user click on that link it will go to another jsp that show complete detail of Student.
3)In one column we provide a link .When user click on that link it will go to another jsp that show complete detail of Student.
4)Also we provide pagination among the list.
Step 1:- Create Liferay Plugin Portlet and Services
First we create a liferay plugin project than create a portlet in this project. Then create sevice.xml and build services. For details of services you can read my Previous Blog.
Project Structure look like :-
Project Structure look like :-
Step 2:-Then Copy the code in view.jsp
Explaination of view.jsp:-
a)String currentURL = PortalUtil.getCurrentURL(request);
By using getCurrentURL we can get the URL of Current Page this url is helpful when we get back from detail page to our current list page.
b)<liferay-ui:search-container delta="5" deltaConfigurable="true">
Here the search container tag start which contain many attribute like:-
delta:- This attribute is used to set by default how many records per page is shown.
deltaConfigurable:- This attribute is used so that end user can change no of records per page.
C)<liferay-ui:search-container-results results=" " total=""/>
This result tag has two main attribute like:-
results:- This attribute contain records with start index and end index . The start index and end index can be get with the help of searchContainer Object.The object of searchContainer is available as soon as we include the import statement:-
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui"%>
Ex- StudentLocalServiceUtil.getStudents(searchContainer.getStart(), searchContainer.getEnd()) %>"
total:- This attribute contain total number of records.
d)<liferay-ui:search-container-row className=" " modelVar="" keyProperty="">
This search container row tag contain attribute:-
className:-This contain the full path of your model Class like Student in this case.
modelVar:- This contain the current object that is available in the row .You can use this to get values and provide in Urls etc.
keyProperty:- Primary key of Model Object.
e)<liferay-ui:search-container-column-text property="" name="" href="" value=""/>
This search container column-text property tag is used to set the value in column.For each column their is one tag.This contain attribute:-
property:- This must be the same as fields mention in Model Class whose getter and setters are available.If this match with instance variables of Model Class(Student) then it get value automatically from current object
name:- Header name of your column.
href:- If you want any action is perform on Clicking of this field then pass Url here.
Value:- Any specific value you want to show on the basis of value of database or any hardcoded value.Otherwise by property tag it will automatically take from current object.
Example:-
<liferay-ui:search-container-column-text name="Gender" value='<%=(aStudent.getGender()==1)?"Male":"Female"%>'/>
Here value is by default is O or 1 but we use Current Object and get Gender and on the basis of result we change the value to Male or Female.
f)<liferay-ui:search-container-column-jsp name="" align="left" path=""/>
If you want to show a particular jsp in some column then you can use this tag by providing complete path of your jsp.
g)<liferay-ui:search-iterator />
This is iterator this tag must come after row tag this iterate the list and create rows.
Step 3:-Then Create a jsp file inside html and paste the content
display_student.jsp
Note:- The back to all link use the URL that is captured by PortalUtil.getCurrentURL(request) in view.jsp and send with renderUrl .So that we can go back to view.jsp again.
Step 4:-Then Create a jsp file inside html and paste the content
address.jsp
Note:- This Complete jsp is directly put in column(search-container-column-jsp tag)
Step 5:-Then Copy the code in your Controller class
SearchContainer.java
f)<liferay-ui:search-container-column-jsp name="" align="left" path=""/>
If you want to show a particular jsp in some column then you can use this tag by providing complete path of your jsp.
g)<liferay-ui:search-iterator />
This is iterator this tag must come after row tag this iterate the list and create rows.
Step 3:-Then Create a jsp file inside html and paste the content
display_student.jsp
Note:- The back to all link use the URL that is captured by PortalUtil.getCurrentURL(request) in view.jsp and send with renderUrl .So that we can go back to view.jsp again.
Step 4:-Then Create a jsp file inside html and paste the content
address.jsp
Note:- This Complete jsp is directly put in column(search-container-column-jsp tag)
Step 5:-Then Copy the code in your Controller class
SearchContainer.java
This code is self explanatory.
Output:-
Hope this will help ...
On Click on Student Name or Detail Control goes to another jsp where we show whole data related to student.
You can Download source code from Here
Hope this will help ...
Related Post:-