Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Satish Babu Anupoju
How to get the articles with category id
December 12, 2011 4:23 AM
Answer

Satish Babu Anupoju

Rank: Junior Member

Posts: 67

Join Date: February 19, 2011

Recent Posts

Hi Friends

Here I have requirement. Can anyone give some solution for this :

1. I have created few categories from control panel.
2. I have created few articles from control panel->webcontent

Note : Now I want to fetch the articles information based on the category id.

In JSP I have dropdown box which contains categores(every category having id). When I select any category immediatly it should display the respective articles.

Thanks & Regards
Satish Babu
Michał Kolenda
RE: How to get the articles with category id
December 12, 2011 5:20 AM
Answer

Michał Kolenda

Rank: New Member

Posts: 18

Join Date: November 25, 2010

Recent Posts

Use method AssetEntryServiceUtil.getEntries(AssetEntryQuery entryQuery). It returns the list of asset entries matching the criterias specified in entryQuery object.
AssetEntryQuery contains fields: _allCategoryIds, _anyCategoryIds, _notAllCategoryIds, _notAnyCategoryIds. You can set them via setters.

Here is sample psudo-code to achieve the list of articles:

 1long categoryId = request.getParameter(...) // get the expected category id (i.e. from request parameter)
 2long classNameId = PortalUtil.getClassNameId(JournalArticle.class.getName());
 3AssetEntryQuery aeq = new AssetEntryQuery();
 4aeq.setAllCategoryIds(new long[]{categoryId});
 5aeq.setClassNameIds(new long []{classNameId});
 6List<AssetEntry> entries = AssetEntryQueryServiceUtil.getEntries(aeq);
 7for (AssetEntry entry : entries) {
 8  String className = PortalUtil.getClassName(entry.getClassNameId();
 9  AssetRendererFactory assetRendererFactory = AssetRendererFactoryRegistryUtil.getAssetRendererFactoryByClassName(className);
10  AssetRenderer assetRenderer = assetRendererFactory.getAssetRenderer(entry.getClassPK());
11  if (assetRenderer instanceof JournalArticleAssetRenderer) {  //should be always true
12    JournalArticleAssetRenderer articleRenderer = (JournalArticleAssetRenderer)assetRenderer;
13    JournalArticle article = articleRenderer.getArticle(); //it is the article you searched
14  }
15}
Siddarth R Mannem
RE: How to get the articles with category id
November 28, 2016 2:48 PM
Answer

Siddarth R Mannem

Rank: New Member

Posts: 1

Join Date: January 19, 2014

Recent Posts

Hi,
I'm looking similar code in velocity template. Not sure how to create instance for "AssetEntryQuery" in velocity vm template. Can you please help me with code ?