Hope you are doing good.
In “Hi I am Liferay” we have seen last two things which might be small but equaly important for Liferay developer.
Requirement description : I have my own custom MVC portlet called fruit portlet which will describe all fruit characteristics and items which made from it, which will be filter base on tag, when user will click on any tag for example an apple all entries which tagged as an apple will display along with description,and only those tags should be display on the page which are associated with custom entity.
Solution :
Step 1) As Tag [Tag cloud or Tag navigation] portlet is different entity we need to work on IPC so when user click on any tag your portlet[custom portlet] should know at time of render page.
To accomplish it you need to do certain things as below.
In portlet.xml of your portlet you need to have following entries.
<portlet-app ........>
<portlet>
<portlet-name>Fruit</portlet-name>
<display-name>This is fruit decstiption</display-name>
<portlet-name>Fruit</portlet-name>
<display-name>This is fruit decstiption</display-name>
|
|
<supported-public-render-parameter>tag</supported-public-render-parameter>
</portlet>
<public-render-parameter>
<identifier>tag</identifier>
<qname xmlns:x="http://www.liferay.com/public-render-parameters">x:tag</qname>
</public-render-parameter>
</portlet-app ........>
Step 2) In JSP of your portlet where you want to display tags related to your entity you need to write following code.
<liferay-ui:asset-tags-navigation
classNameId="<%= classNameId %>"
displayStyle="<%= displayStyle %>"
hidePortletWhenEmpty="<%= true %>"
maxAssetTags="<%= maxAssetTags %>"
showAssetCount="<%= showAssetCount %>"
showZeroAssetCount="<%= showZeroAssetCount %>"
/>
Where
1.classNameId (long) = your entity class name id for which you need to display tags, in our case we will get it as below
long clssNameId = com.liferay.portal.util.PortalUtil.getClassNameId(FruitEntry.class.getName());
2.displayStyle (String) = We will give here "cloud" as we want tag cloud look rather navigation.
3.hidePortletWhenEmpty (Boolean)= if true it will hide portlet when there is no related tags found
4.maxAssetTags (int) = number of tags to be displayed on the page.
5.showAssetCount (Boolean) = true
6.showZeroAssetCount (Bollean) = false
Step 3) In controller class in doView() method of portlet every time you need to check as follow.
String tagName = renderRequest.getParameter("tag");
when user click on any tag [on tag cloud portlet] you will get tag name in doView()
as tagName as shown in code above, now you can right some code which will bring list of assets
which is associated with clicked tag.
Hope this helps.
For more information you can contact on sagar.vyas.blogspot@gmail.com
Thanks,
Sagar Vyas