Friday 30 March 2012

Filtering Asset Publisher by category

Hello,
    This post I'll describe how to implement filtering for Asset Publisher by categories.

    It can be done by hooking asset publisher portlet pages.
    First let's add some form with select category we want to filter of. For this add next code before line:


    
        <%@ include file="/html/portlet/asset_publisher/view_dynamic_list.jspf" %>
    
      to hook/docroot/META-INF/custom_jsps/html/portlet/asset_publisher/view.jsp:
 <%
   long[] selectedCategories = new long[] {};
      Long category1 = ParamUtil.getLong(request, "category1");
     
      List categories = AssetCategoryLocalServiceUtil.getVocabularyCategories(categVocabularyId, 0, Integer.MAX_VALUE, null);
        ArrayList selectedCategoriesList = new ArrayList();
      
      if (category1 > 0) {
        selectedCategoriesList.add(category1);
      }
      
   if (selectedCategoriesList.size() > 0) {
       selectedCategories = new long[selectedCategoriesList.size()];
       for (int i = 0; i<=selectedCategoriesList.size()-1; i++) {
         selectedCategories[i] = selectedCategoriesList.get(i);
       }
   }
     %>
     
  
   
   
     <%
      for (AssetCategory category : categories) {
     %>
      
     <%
      }
     %>
                    
    
  
  
   function submitForm() {
    submitForm(document.fmCat);
   }
  
      Second, hook up jsp hook\docroot\META-INF\custom_jsps\html\portlet\asset_publisher\view_dynamic_list.jspf. And add to it at line 138:
 if (selectedCategories.length > 0) {
     assetEntryQuery.setAllCategoryIds(selectedCategories);
 }

     As a result you will have AssetPublisher with chosser of categories to filter of.

    This approach will work for dynamic lists of assets. Also you can add your own view with filtering to AssetPublisher.

BR,
Paul

3 comments:

  1. Help Please

    Error: /html/portlet/asset_publisher/view.jsp (line: 138, column: 4) No tag "actionurl" defined in tag library imported with prefix "liferay-portlet"

    ReplyDelete
  2. Hi,
    It should be liferay-portlet:actionURL instead of liferay-portlet:actionurl.

    ReplyDelete
  3. Could please do the samething in Liferay 6.2?

    ReplyDelete