title: Liferay 6.2 Media Gallery
body: <p><a href="https://i.stack.imgur.com/hWkZB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hWkZB.jpg" alt="enter image description here"></a>
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;%--
  /**
   * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
   *
   * This library is free software; you can redistribute it and/or modify it under
   * the terms of the GNU Lesser General Public License as published by the Free
   * Software Foundation; either version 2.1 of the License, or (at your option)
   * any later version.
   *
   * This library is distributed in the hope that it will be useful, but WITHOUT
   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
   * details.
   */
  --%&gt;
  
  &lt;%@ include file="/html/portlet/image_gallery_display/init.jsp" %&gt;
  
  &lt;%
  Folder folder = (Folder)request.getAttribute(WebKeys.DOCUMENT_LIBRARY_FOLDER);
  
  long defaultFolderId = GetterUtil.getLong(portletPreferences.getValue("rootFolderId", StringPool.BLANK), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);
  
  long folderId = BeanParamUtil.getLong(folder, request, "folderId", defaultFolderId);
  
  boolean defaultFolderView = false;
  
  if ((folder == null) &amp;&amp; (defaultFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {
   defaultFolderView = true;
  }
  
  if (defaultFolderView) {
   try {
    folder = DLAppLocalServiceUtil.getFolder(folderId);
   }
   catch (NoSuchFolderException nsfe) {
    folderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
   }
  }
  
  long repositoryId = scopeGroupId;
  
  if (folder != null) {
   repositoryId = folder.getRepositoryId();
  }
  
  int status = WorkflowConstants.STATUS_APPROVED;
  
  if (permissionChecker.isContentReviewer(user.getCompanyId(), scopeGroupId)) {
   status = WorkflowConstants.STATUS_ANY;
  }
  
  long portletDisplayDDMTemplateId = PortletDisplayTemplateUtil.getPortletDisplayTemplateDDMTemplateId(displayStyleGroupId, displayStyle);
  %&gt;
  
  &lt;c:choose&gt;
   &lt;c:when test="&lt;%= portletDisplayDDMTemplateId &gt; 0 %&gt;"&gt;
  
    &lt;%
    String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
  
    List fileEntries = DLAppServiceUtil.getGroupFileEntries(scopeGroupId, 0, folderId, mediaGalleryMimeTypes, status, 0, SearchContainer.MAX_DELTA, null);
    %&gt;
  
    &lt;%= PortletDisplayTemplateUtil.renderDDMTemplate(pageContext, portletDisplayDDMTemplateId, fileEntries) %&gt;
   &lt;/c:when&gt;
   &lt;c:otherwise&gt;
  
    &lt;%
    String topLink = ParamUtil.getString(request, "topLink", "home");
  
    long assetCategoryId = ParamUtil.getLong(request, "categoryId");
    String assetTagName = ParamUtil.getString(request, "tag");
  
    boolean useAssetEntryQuery = (assetCategoryId &gt; 0) || Validator.isNotNull(assetTagName);
  
    PortletURL portletURL = renderResponse.createRenderURL();
  
    portletURL.setParameter("struts_action", "/image_gallery_display/view");
    portletURL.setParameter("topLink", topLink);
    portletURL.setParameter("folderId", String.valueOf(folderId));
  
    request.setAttribute("view.jsp-folder", folder);
  
    request.setAttribute("view.jsp-defaultFolderId", String.valueOf(defaultFolderId));
  
    request.setAttribute("view.jsp-folderId", String.valueOf(folderId));
  
    request.setAttribute("view.jsp-repositoryId", String.valueOf(repositoryId));
  
    request.setAttribute("view.jsp-viewFolder", Boolean.TRUE.toString());
  
    request.setAttribute("view.jsp-useAssetEntryQuery", String.valueOf(useAssetEntryQuery));
  
    request.setAttribute("view.jsp-portletURL", portletURL);
    %&gt;
  
    &lt;portlet:actionURL var="undoTrashURL"&gt;
     &lt;portlet:param name="struts_action" value="/document_library/edit_entry" /&gt;
     &lt;portlet:param name="&lt;%= Constants.CMD %&gt;" value="&lt;%= Constants.RESTORE %&gt;" /&gt;
    &lt;/portlet:actionURL&gt;
  
    &lt;liferay-ui:trash-undo portletURL="&lt;%= undoTrashURL %&gt;" /&gt;
  
    &lt;liferay-util:include page="/html/portlet/document_library/top_links.jsp" /&gt;
  
    &lt;c:choose&gt;
     &lt;c:when test="&lt;%= useAssetEntryQuery %&gt;"&gt;
      &lt;liferay-ui:categorization-filter
       assetType="images"
       portletURL="&lt;%= portletURL %&gt;"
      /&gt;
  
      &lt;%
      SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, "cur2", SearchContainer.DEFAULT_DELTA, portletURL, null, null);
      
      OrderByComparator orderByComparator = DLUtil.getRepositoryModelOrderByComparator("modifiedDate", "desc");
  searchContainer.setOrderByComparator(orderByComparator);
      
  
      long[] classNameIds = {PortalUtil.getClassNameId(DLFileEntryConstants.getClassName()), PortalUtil.getClassNameId(DLFileShortcut.class.getName())};
  
      AssetEntryQuery assetEntryQuery = new AssetEntryQuery(classNameIds, searchContainer);
  
      assetEntryQuery.setEnablePermissions(true);
      assetEntryQuery.setExcludeZeroViewCount(false);
  
      int total = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);
  
      searchContainer.setTotal(total);
  
      List results = AssetEntryServiceUtil.getEntries(assetEntryQuery);
  
      searchContainer.setResults(results);
  
      String[] mediaGalleryMimeTypes = null;
  
      request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
      request.setAttribute("view.jsp-searchContainer", searchContainer);
      %&gt;
  
      &lt;liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" /&gt;
     &lt;/c:when&gt;
     &lt;c:when test='&lt;%= topLink.equals("home") %&gt;'&gt;
      &lt;aui:row&gt;
       &lt;c:if test="&lt;%= folder != null %&gt;"&gt;
        &lt;liferay-ui:header
         localizeTitle="&lt;%= false %&gt;"
         title="&lt;%= folder.getName() %&gt;"
        /&gt;
       &lt;/c:if&gt;
  
       &lt;%
       SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, "cur2", SearchContainer.DEFAULT_DELTA, portletURL, null, null);
  
       String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
  
       int foldersCount = DLAppServiceUtil.getFoldersCount(repositoryId, folderId, true);
  
       int total = DLAppServiceUtil.getFoldersAndFileEntriesAndFileShortcutsCount(repositoryId, folderId, status, mediaGalleryMimeTypes, true);
  
       int imagesCount = total - foldersCount;
  
       searchContainer.setTotal(total);
  
       List results = DLAppServiceUtil.getFoldersAndFileEntriesAndFileShortcuts(repositoryId, folderId, status, mediaGalleryMimeTypes, true, searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());
  
       searchContainer.setResults(results);
  
       request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
       request.setAttribute("view.jsp-searchContainer", searchContainer);
       %&gt;
  
       &lt;aui:col cssClass="lfr-asset-column lfr-asset-column-details" width="&lt;%= showFolderMenu ? 75 : 100 %&gt;"&gt;
        &lt;div id="&lt;portlet:namespace /&gt;imageGalleryAssetInfo"&gt;
         &lt;c:if test="&lt;%= folder != null %&gt;"&gt;
          &lt;div class="lfr-asset-description"&gt;
           &lt;%= HtmlUtil.escape(folder.getDescription()) %&gt;
          &lt;/div&gt;
  
          &lt;div class="lfr-asset-metadata"&gt;
           &lt;div class="lfr-asset-icon lfr-asset-date"&gt;
            &lt;%= LanguageUtil.format(pageContext, "last-updated-x", dateFormatDate.format(folder.getModifiedDate())) %&gt;
           &lt;/div&gt;
  
           &lt;div class="lfr-asset-icon lfr-asset-subfolders"&gt;
            &lt;%= foldersCount %&gt; &lt;liferay-ui:message key='&lt;%= (foldersCount == 1) ? "subfolder" : "subfolders" %&gt;' /&gt;
           &lt;/div&gt;
  
           &lt;div class="lfr-asset-icon lfr-asset-items last"&gt;
            &lt;%= imagesCount %&gt; &lt;liferay-ui:message key='&lt;%= (imagesCount == 1) ? "image" : "images" %&gt;' /&gt;
           &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;liferay-ui:custom-attributes-available className="&lt;%= DLFolderConstants.getClassName() %&gt;"&gt;
           &lt;liferay-ui:custom-attribute-list
            className="&lt;%= DLFolderConstants.getClassName() %&gt;"
            classPK="&lt;%= (folder != null) ? folder.getFolderId() : 0 %&gt;"
            editable="&lt;%= false %&gt;"
            label="&lt;%= true %&gt;"
           /&gt;
          &lt;/liferay-ui:custom-attributes-available&gt;
         &lt;/c:if&gt;
  
         &lt;liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" /&gt;
        &lt;/div&gt;
       &lt;/aui:col&gt;
  
       &lt;c:if test="&lt;%= showFolderMenu %&gt;"&gt;
        &lt;aui:col cssClass="lfr-asset-column lfr-asset-column-actions" last="&lt;%= true %&gt;" width="&lt;%= 25 %&gt;"&gt;
         &lt;div class="lfr-asset-summary"&gt;
          &lt;liferay-ui:icon
           cssClass="lfr-asset-avatar"
           image='&lt;%= "../file_system/large/" + ((total &gt; 0) ? "folder_full_image" : "folder_empty") %&gt;'
           message='&lt;%= (folder != null) ? HtmlUtil.escape(folder.getName()) : LanguageUtil.get(pageContext, "home") %&gt;'
          /&gt;
  
          &lt;div class="lfr-asset-name"&gt;
           &lt;h4&gt;&lt;%= (folder != null) ? HtmlUtil.escape(folder.getName()) : LanguageUtil.get(pageContext, "home") %&gt;&lt;/h4&gt;
          &lt;/div&gt;
         &lt;/div&gt;
  
         &lt;%
         request.removeAttribute(WebKeys.SEARCH_CONTAINER_RESULT_ROW);
         %&gt;
  
         &lt;liferay-util:include page="/html/portlet/document_library/folder_action.jsp" /&gt;
        &lt;/aui:col&gt;
       &lt;/c:if&gt;
      &lt;/aui:row&gt;
  
      &lt;%
      if (folder != null) {
       IGUtil.addPortletBreadcrumbEntries(folder, request, renderResponse);
  
       if (!defaultFolderView &amp;&amp; portletName.equals(PortletKeys.MEDIA_GALLERY_DISPLAY)) {
        PortalUtil.setPageSubtitle(folder.getName(), request);
        PortalUtil.setPageDescription(folder.getDescription(), request);
       }
      }
      %&gt;
  
     &lt;/c:when&gt;
     &lt;c:when test='&lt;%= topLink.equals("mine") || topLink.equals("recent") %&gt;'&gt;
  
      &lt;%
      long groupImagesUserId = 0;
  
      if (topLink.equals("mine") &amp;&amp; themeDisplay.isSignedIn()) {
       groupImagesUserId = user.getUserId();
      }
  
      SearchContainer searchContainer = new SearchContainer(renderRequest, null, null, SearchContainer.DEFAULT_CUR_PARAM, SearchContainer.DEFAULT_DELTA, portletURL, null, null);
  
      String[] mediaGalleryMimeTypes = DLUtil.getMediaGalleryMimeTypes(portletPreferences, renderRequest);
  
      int total = DLAppServiceUtil.getGroupFileEntriesCount(repositoryId, groupImagesUserId, defaultFolderId, mediaGalleryMimeTypes, status);
  
      searchContainer.setTotal(total);
  
      List results = DLAppServiceUtil.getGroupFileEntries(repositoryId, groupImagesUserId, defaultFolderId, mediaGalleryMimeTypes, status, searchContainer.getStart(), searchContainer.getEnd(), searchContainer.getOrderByComparator());
  
      searchContainer.setResults(results);
  
      request.setAttribute("view.jsp-mediaGalleryMimeTypes", mediaGalleryMimeTypes);
      request.setAttribute("view.jsp-searchContainer", searchContainer);
      %&gt;
  
      &lt;aui:row&gt;
       &lt;liferay-ui:header
        title="&lt;%= topLink %&gt;"
       /&gt;
  
       &lt;liferay-util:include page="/html/portlet/image_gallery_display/view_images.jsp" /&gt;
      &lt;/aui:row&gt;
  
      &lt;%
      PortalUtil.addPortletBreadcrumbEntry(request, LanguageUtil.get(pageContext, topLink), currentURL);
  
      PortalUtil.setPageSubtitle(LanguageUtil.get(pageContext, topLink), request);
      %&gt;
  
     &lt;/c:when&gt;
    &lt;/c:choose&gt;
   &lt;/c:otherwise&gt;
  &lt;/c:choose&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>i m using Liferay 6.2 and using Media Gallery Portlet to display the images which is placed in Multiple folders. i have multiple folders which contain multiple images but the folders are arranged according to alphabetical order but my requirement is to arrange the folders which are recently updated (i,e the recently updated folder must come at the top) so can anybody please provide solution how to achieve this.</p>
  
  <p>thanks in Advance.</p>