Foros de discusión

How can I create a list of content filtered by categories ?

Michele Celli, modificado hace 12 años.

How can I create a list of content filtered by categories ?

Junior Member Mensajes: 33 Fecha de incorporación: 18/04/11 Mensajes recientes
Hello to all,
I'd need to filter a list of web content using Categories.
In my portlet I have created a configuration page where I use the follow control

<liferay-ui: asset categories-selector curCategoryIds ="<%= categories%> "hiddenInput =" categories "/>

Once the data is saved, I try to use them in my portlets, maybe I wrong the way to pass data to DynamicQuery, below is the code:


	PortletPreferences preferences = renderRequest.getPreferences();
	
	String categories = preferences.getValue( "categories", "" );
	
        /* Categories Filter */
	if( !categories.isEmpty() ) {
		String	categoriesA[]		= (String[]) null;
		Long resourcePrimKeys[]	= null;
		   
		categoriesA = StringUtil.split( categories, "," );
 		long categoryIds[] = new long[ categoriesA.length ];
		for( int c = 0; c &lt; categoriesA.length; c++ ) {
			categoryIds[c] = Long.parseLong( categoriesA[c] );
		}
			
	    	if( categoryIds.length &gt; 0 ) {
			AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
			assetEntryQuery.setAnyCategoryIds( categoryIds );
			List assetEntries = assetEntries = AssetEntryServiceUtil.getEntries( assetEntryQuery );
			if( assetEntries != null &amp;&amp; !assetEntries.isEmpty() ) {
				resourcePrimKeys = new Long[assetEntries.size()];
				int index = 0;
				for( Iterator iterator = assetEntries.iterator(); iterator.hasNext(); ) {
					AssetEntry assetEntry = (AssetEntry)iterator.next();
					resourcePrimKeys[index++] = Long.valueOf( assetEntry.getClassPK() );
				}
			}
	    	}
		
		if( resourcePrimKeys == null ) { resourcePrimKeys = new Long[1]; }
		
		dynamicQuery.add( PropertyFactoryUtil.forName( "resourcePrimKey" ).in( resourcePrimKeys ) );	
	}

	List myArticles = JournalArticleLocalServiceUtil.dynamicQuery( dynamicQuery );


I hope someone can help me, I'm really desperate!
Best regards
Michele
Michele Celli, modificado hace 12 años.

RE: How can I create a list of content filtered by categories ?

Junior Member Mensajes: 33 Fecha de incorporación: 18/04/11 Mensajes recientes
Anyone can help me pls ?
thumbnail
Raju OO7, modificado hace 12 años.

RE: How can I create a list of content filtered by categories ?

Regular Member Mensajes: 239 Fecha de incorporación: 27/04/10 Mensajes recientes
List assetEntries = assetEntries = AssetEntryServiceUtil.getEntries( assetEntryQuery ); wt is this boss??? emoticon

is it List assetEntries = AssetEntryLocalServiceUtil.getEntries( assetEntryQuery )???

check whether u r getting entries count properly before using dynamic query. !!
use this method for that ..
System.out.println("count: " + AssetEntryLocalServiceUtil.getEntries(assetEntryQuery).size());
Michele Celli, modificado hace 12 años.

RE: How can I create a list of content filtered by categories ?

Junior Member Mensajes: 33 Fecha de incorporación: 18/04/11 Mensajes recientes
Hello Raju,
I'm sorry if I answer with a little late, thanks for your answer. I corrected the code and now I have solved.

Now if I can take advantage, I would have another question, when I take the list of web content there are also those with the older version, how can I to shut them out ?

Thank in advance