Ajax Pagination in Liferay Search Container

1.5k views Asked by At

I am trying to Ajax Call on Search Container Pagination. As there are more than one portlet on same page I don't want to each portlet to forcefully call render every time when I do Pagination.

There could be 2 possible solutions but I am facing some problem. Please help me to solve it.

1) Can you please tell me how to edit Liferay Search Container Pagination URL by changing its Portlet Life-cycle from 0 to 2 ? How to create hook ?

2) There is a tag called <liferay-ui:page-iterator/> in which there is a attribute called jsCall. It is used for pagination without page reloading. I am unable to find out how to use it ?

If it can be solved using 2nd option then it would be much helpful.

Thank You.

2

There are 2 answers

1
Jorge B. On

kanakhara,

Each time I faced that problem I had to implement manually a pagination because search-container is really embedded to be modified by a developer.

Maybe could be a solution to this problem but it's not sure that it exists. You'll spend less time creating your own pagination for this purpose.

I hope it can help you.

Best wishes

0
Jorge B. On

Yes, I know how to use it.

I'll give you an example to do it:

<portlet:renderURL var="manageRelationsURL"
windowState="<%=LiferayWindowState.NORMAL.toString()%>">
<portlet:param name="action" value="manageRelations" />
</portlet:renderURL>

<%PortletURL iteratorURL = renderResponse.createRenderURL();
iteratorURL.setParameter("action", "manageRelations");
%>

    <%
PortalPreferences portalPrefs = PortletPreferencesFactoryUtil.getPortalPreferences(request);
String orderByCol = ParamUtil.getString(request, "orderByCol");
String orderByType = ParamUtil.getString(request, "orderByType");


if (Validator.isNotNull(orderByCol) && Validator.isNotNull(orderByType)) {
    portalPrefs.setValue("NAME_SPACE", "order-by-col", orderByCol);
    portalPrefs.setValue("NAME_SPACE", "order-by-type", orderByType);

} else {
    orderByCol = portalPrefs.getValue("NAME_SPACE", "order-by-col", "domainLabel");
    orderByType = portalPrefs.getValue("NAME_SPACE", "order-by-type", "asc");

}
 %>
<div style="">
<aui:form>
<liferay-ui:search-container delta="20" iteratorURL="<%=iteratorURL%>" emptyResultsMessage="There were not any match." orderByCol="<%= orderByCol %>" orderByType="<%= orderByType %>">
<liferay-ui:search-form
    page="/WEB-INF/jsp/localAdministration/relations/search.jsp"
    searchContainer="<%= searchContainer %>"
    servletContext="<%= this.getServletConfig().getServletContext() %>"
    showAddButton="true" />
    <liferay-ui:search-container-results>

        <%
        List<RelationInstance> relationList = UtilsAdministration.getRelationListCache(themeDisplay.getUserId(),0, UtilsAdministration.getRelationListCacheSize(themeDisplay.getUserId()));
        Collections.sort(relationList,RelationsComparator.getRelationsOrderByComparator(orderByCol, orderByType));

        results = ListUtil.subList(relationList, searchContainer.getStart(),   
                 searchContainer.getEnd());

           if(relationList.size()<searchContainer.getEnd()){
               results = ListUtil.subList(relationList, searchContainer.getStart(),   
                       relationList.size());
               total = relationList.size();
           }else{
               results = ListUtil.subList(relationList, searchContainer.getStart(),   
                       searchContainer.getEnd());
               total = relationList.size();
           }

           pageContext.setAttribute("results", results);
           pageContext.setAttribute("total", total);
        %>
        </liferay-ui:search-container-results>


    <liferay-ui:search-container-row className="RelationInstance" modelVar="aRelationInstance">
        <liferay-ui:search-container-column-text name="First" value="<%=aRelationInstance.getFirstLabel()%>" orderable="<%= true %>" orderableProperty="domainLabel"/>
        <liferay-ui:search-container-column-text name="Second" value="<%=aRelationInstance.getSecondLabel()%>" orderable="<%= true %>" orderableProperty="relationLabel"/>
        <liferay-ui:search-container-column-text name="Third" value="<%=aRelationInstance.getRangeLabel()%>" orderable="<%= true %>" orderableProperty="rangeLabel"/>
        <liferay-ui:search-container-column-jsp align="right" name="Acciones" path="/WEB-INF/jsp/localAdministration/relations/actionRelationButton.jsp"/>  
    </liferay-ui:search-container-row>
    <liferay-ui:search-iterator />
</liferay-ui:search-container>
</aui:form>
</div>

In this case I retrieve the list to iterate from EhCache instead of DB.

IteratorURL must contains the same URL that the page you're invoking.

I hope it could be useful for you.