Saturday, August 29, 2015

Fetch/Retrieve Web Content (By Providing Structures and Categories) Programmaticlly in Liferay


Today we will discuss how to Retrieve/Fetch a web content by providing categories and structures in Liferay. Basically we filter Web contents as our Asset Publisher portlet do in Liferay.Before reading this blog you must know how to Create Categories, Structures and Templates. For this you may refer my previous blogs on Web Contents.

For this I already created 3 things:-

1)Categories:- Nokia, Sony and Camera . 
2)Web Contents:- I also created 4 web Contents and associated with Categories as:- 

  • Nokia 1600-->Nokia
  • Nokia Lumia 520--> Nokia and Camera
  • Sony Xperia C --> Sony and Camera
  • Sony Xperia L --> Sony and Camera

3)Structure:- MOBILE_STRUCTURE

So lets start step by step:-





Step 1:-Create Liferay Project and Portlet
Create a Liferay Project in eclipse and then create a portlet in the Project.For theses you may refer Step 1 and Step 2 of my previous blog Here .

Step 2:-Fetch Structure Ids by Structure Names
For filtering on the basis of Structures first we have to find Structure Ids by providing Structure Names as:-



Step 3:-Fetch Category Ids by Category Names
For filtering on the basis of Categories, we have to find category Ids by providing Category Names as:-



Step 4:-Fetch Asset Entries by Creating Query
Now we have Structure Ids(By Step 1) and Category Id(By Step 2) so create a AssetQuery and get List of Asset Entries by providing both:-


Explanation:-
Here we create a AssetEntryQuery Object which contain many methods to filter out the result.Ex - setAllCategoryIds which represent OR operation between Categories.







Step 5:-Get Web Contents by AssetEnties
In Step 3 we have List of AssetEntries Now we fetch web contents by Providing AssetEntries as:-


Now by Writing all methods .My Controller become:-



Step 6:-Output

1)If input is:-

Then Output is:-
Title=>Nokia Lumia 520

2)If input is:-

No comments:

Post a Comment

Total Pageviews

Like Us on Facebook

Number Of Unique Visitor

Free counters!