Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use two (multiple) Liferay UI Search Container tags in a single JSP

I need to use two different <liferay-ui:search-container> tags in a single JSP.

The pagination gives issues if we use two <liferay-ui:search-container> tags:

  1. When I click on the 3rd page of the first <liferay-ui:search-container> tag the second <liferay-ui:search-container> tag also moves to the third page.

  2. Also if for the first <liferay-ui:search-container> tag I am on page-3 and I click page-2 of second <liferay-ui:search-container> tag then the second tag goes to page-2 but the first tag results is reset to page-1.

They should be independent of each other.

Environment: Liferay 6.+

like image 252
Prakash K Avatar asked Jul 17 '12 12:07

Prakash K


1 Answers

I found two different ways to do this:

  1. This is possible through the use of curParam attribute in <liferay-ui:search-container> tag, noticed the curParam="folderCurParam" and curParam="fileCurParam" in the following code, I found this way through liferay's source code docroot/html/portlet/document_library_display/view.jsp and docroot/html/portlet/document_library_display/view_file_entries.jspf:

    <liferay-ui:search-container
            curParam="folderCurParam"
            emptyResultsMessage="no-folders-to-display"  
            iteratorURL="<%= portletURL %>"
            delta="10">
    
        <liferay-ui:search-container-results
                results="<%=folderResults %>"
                total="<%= folderTotal %>" />
    
        <liferay-ui:search-container-row
                className="com.liferay.portal.kernel.repository.model.Folder"
                keyProperty="userId"
                modelVar="folder">
    
            <liferay-ui:search-container-column-jsp align="left"
                    path="/html/documentdisplay/folder_search_results.jsp" />
    
        </liferay-ui:search-container-row>
    
        <liferay-ui:search-iterator />
    
    </liferay-ui:search-container>
    
    <liferay-ui:search-container
            curParam="fileCurParam"
            emptyResultsMessage="no-files-to-display" 
            iteratorURL="<%= portletURL %>"
            delta="10">
        <liferay-ui:search-container-results
                results="<%=fileResults %>"
                total="<%= fileTotal %>" />
    
        <liferay-ui:search-container-row
                className="com.liferay.portal.kernel.repository.model.FileEntry"
                keyProperty="userId"
                modelVar="fileEntry">
    
            <liferay-ui:search-container-column-jsp align="left"
                    path="/html/documentdisplay/files_search_results.jsp" />
    
        </liferay-ui:search-container-row>
    
        <liferay-ui:search-iterator />
    
    </liferay-ui:search-container>
    
  2. I found this again in liferay's source code docroot/html/portlet/journal/select_document_library.jsp, this uses the SearchContainer constructor to set the curParam, notice the parameter "cur1" for folders and for files it is "cur2":

    // for folders
    SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, "cur1", SearchContainer.DEFAULT_DELTA, portletURL, headerNames, "there-are-no-folders");
    
    // for files
    searchContainer = new SearchContainer(renderRequest, null, null, "cur2", SearchContainer.DEFAULT_DELTA, portletURL, headerNames, "there-are-no-documents-in-this-folder");
    

Hope this helps someone.

like image 179
Prakash K Avatar answered Dec 03 '22 16:12

Prakash K