Liferay Search Container Example

Or how to implement a custom search container in Liferay


Overview 
Search Containers are used in Liferay to display the table data. This article shows a simple example of how to implement a custom search container. 


Example


<liferay-portlet:renderURL varImpl="iteratorURL" />
<liferay-ui:search-container total="<%= ProjectLocalServiceUtil.getProjectsCount(scopeGroupId) %>"
                            delta="10"
                            emptyResultsMessage="no-projects-found"
                            iteratorURL="<%=iteratorURL%>">
   <liferay-ui:search-container-results
           results="<%= ProjectLocalServiceUtil.getProjects(scopeGroupId, searchContainer.getStart(), searchContainer.getEnd()) %>"/>
   <liferay-ui:search-container-row className="com.sample.sb.model.Project" modelVar="project" keyProperty="projectId">
       <liferay-ui:search-container-column-text name="project.projectId" value="${project.projectId}" />
       <liferay-ui:search-container-column-text name="project.title" value="${project.title}" />
       <liferay-ui:search-container-column-text name="project.description" value="${project.description}" />
       <liferay-ui:search-container-column-text name="actions.label">
           <liferay-ui:icon-menu direction="left-side" icon="" markupView="lexicon" message="actions" showWhenSingleIcon="<%= true %>">
               <portlet:renderURL var="editProjectURL">
                   <portlet:param name="mvcRenderCommandName" value="/projects/edit_project" />
                   <portlet:param name="projectId" value="<%= String.valueOf(project.getProjectId()) %>" />
               </portlet:renderURL>
               <liferay-ui:icon message="action.edit" url="${editProjectURL}" />
               <portlet:actionURL var="deleteProjectURL" name="/projects/delete_project">
                   <portlet:param name="projectId" value="<%= String.valueOf(project.getProjectId()) %>" />
               </portlet:actionURL>
               <liferay-ui:icon message="action.delete" url="${deleteProjectURL}" />
           </liferay-ui:icon-menu>
       </liferay-ui:search-container-column-text>
   </liferay-ui:search-container-row>
   <liferay-ui:search-iterator markupView="lexicon" />
</liferay-ui:search-container>


Key Points


<liferay-portlet:renderURL varImpl="iteratorURL" /> Defines the URL for iterator (pagination);


<liferay-ui:search-container/> defines basic search container properties:
  • total - total count of entities;
  • delta - items per page by default;
  • emptyResultsMessage - the message, which should be displayed, when no results found;
  • iteratorUrl - the URL for iterator;


<liferay-ui:search-container-results/> defines the results for the current page (in “results” attribute).


<liferay-ui:search-container-row/> defines information about the entity displayed in the search container:
  • className - entity class name;
  • modelVal - local variable for the entity object;
  • keyProperty - entity key property (usually the primary key in database);


<liferay-ui:search-container-column-text/> defines column information:
  • name - the caption of column;
  • value - the cell value;

<liferay-ui:search-iterator markupView="lexicon" /> renders the paginator in the bottom.

Enjoy 😏

Comments

Popular posts from this blog

Installing Blade CLI from Command Line

Liferay Keycloak integration