Forums de discussion

Adding Ratings to portles - classPK?

Blaine Boule, modifié il y a 14 années.

Adding Ratings to portles - classPK?

New Member Publications: 15 Date d'inscription: 02/12/09 Publications récentes
I have added ratings to custom portlets according to this article http://www.liferay.com/community/wiki/-/wiki/Main/Adding+Rating+to+a+portlet

I have it working using arbitrary integers for the classPK - or supplying the themes PLID - but for my custom portlets I have developed, how do i get the classPK for it?

Meaning, I have deployed a custom JSP/Flex portlet, i need the classPK so that the rating mapped to that portlet class - but I cannot seem to get the PK. The article says to use yourportlet.getResourcePrimKey() - but this doesnt exist on my portlet object.

Any suggestions?

Lastly, say I write a specific wrapper portlet that holds flex content, it uses a generic portlet class that I have written - but allows me to define multiple portlets in the portlet.xml all using the same class, but different view.jsp's and flex app embedded within. I want to have the users rate the portlet based on the flex app inside, but if it only ties to the classPK - wont all the portlets share the ratings? (being that it ties back to the class and not the portlet configuration)

Thanks
thumbnail
Sandeep Nair, modifié il y a 14 années.

RE: Adding Ratings to portles - classPK?

Liferay Legend Publications: 1744 Date d'inscription: 06/11/08 Publications récentes
What is it that you want to give rating. It might be a unique content of some user or community, that someone might be trying to give a rating to. classPK and className are just a unique id that it need.

Regards,
Sandeep
Blaine Boule, modifié il y a 14 années.

RE: Adding Ratings to portles - classPK?

New Member Publications: 15 Date d'inscription: 02/12/09 Publications récentes
We want to be able to allow users to rate the content of the portlet. From my understanding the classPK ties to the specific java class that renders the portlet. In this instance, the java class is shared among many configurations of that portlet.

For example, we have a flex portlet, that allows the user to configure it to display a flex application, we want the rating to tie to the configuration NOT the portlet wrapper. In this example, I can configure the flex wrapper to display flexApp1, and then add another instance of flex wrapper to the page, configure it to display flexApp2 - but when rating these - if we use classPK, will the ratings for flexApp1 show up on flexApp2 as well (because behind the scenes they both use the same java class to render)

I hope I am expressing this clearly enough to understand.

Regarding my initial question, How do I get classPK for my portlet? I cannot get any method to return the actual PK.

Thanks
thumbnail
Samir C Bhatt, modifié il y a 14 années.

RE: Adding Ratings to portles - classPK?

New Member Publications: 10 Date d'inscription: 26/08/09 Publications récentes
Hi,

For your requirement you need ratings for content and not for the Portlet. So for example in Wiki Portlet, when we give rating they are stored against WikiPage class name and WikiPage instances primary key. So this ratings are per content and not for the portlet.

To achieve same thing you need to have a model class representing your content like WikiPage. If you have such class then you can use its classname and its resource pk in ratings tag.

Now if you dont have any such class then you can probably use PortletPreferences class for your requirement. Issue with this approach will be that if you have 2 portlet instances representing same flex applicatio1 then also it will not present the same ratings. But if it is not a requirement to have 2 portlet instances with same flex application in the configuration then you can use portlet preferences for your requirement in following

<%
	com.liferay.portal.model.PortletPreferences prefs = 
	com.liferay.portal.service.PortletPreferencesLocalServiceUtil.getPortletPreferences 
	(com.liferay.portal.util.PortletKeys.PREFS_OWNER_ID_DEFAULT , 
	com.liferay.portal.util.PortletKeys.PREFS_OWNER_TYPE_LAYOUT, 
	themeDisplay.getPlid(), themeDisplay.getPortletDisplay().getId());
	
%>


<liferay-ui:ratings className="<%= com.liferay.portal.model.PortletPreferences.class.getName() %>" classPK="<%= wikiPage.getPrimaryKey() %>" url="<%= themeDisplay.getPathMain() + &quot;/relativepathtoaction&quot; %>" />



Regards,

Samir Bhatt
CIGNEX Technologies
Blaine Boule, modifié il y a 14 années.

RE: Adding Ratings to portles - classPK?

New Member Publications: 15 Date d'inscription: 02/12/09 Publications récentes
Samir,

This makes sense, but preference wont work because of the issue you mentioned. We dont however, have a model class representing the content, but from my understanding this shouldn't be a difficult task because even though we are using the same JAVA class, we have defined several portlets in the portlet.xml (using same class) - when deployed these get entered into the PORTLET table of the database. Now, in that table the PORTLETID (that I have specified - mapping to portlet-name) get entered as a new row for every portlet defined in my Portlet.xml, correct? So I should be able to use PORTLET table's PK field to link back to my ratings (ie using Liferays Portlet Model and PK to establish ratings).

Example Portlet.xml:


<portlet-app version="1.0" xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
	<portlet>
		<portlet-name>samples1</portlet-name>
		<portlet-class>samples.flex.FlexPortlet</portlet-class>
		<portlet-info>
			<title>Sample Flex Portlet (Publisher)</title>
			<short-title></short-title>
		</portlet-info>
		<init-param>
			<name>view-jsp</name>
			<value>/WEB-INF/pages/flex/publisher/view.jsp</value>
		</init-param>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>VIEW</portlet-mode>
		</supports>
		<supported-locale>en</supported-locale>
		<portlet-preferences>
			<preference>
				<name>eventNamePref</name>
				<value>sampleEvent</value>
			</preference>
			<preference>
				<name>title</name>
				<value>Sample Flex Portlet (Publisher)</value>
			</preference>
		</portlet-preferences>
	</portlet>
	<portlet>
		<portlet-name>samples2</portlet-name>
		<portlet-class>samples.flex.FlexPortlet</portlet-class>
		<portlet-info>
			<title>Sample Flex Portlet (Subscriber)</title>
			<short-title></short-title>
		</portlet-info>
		<init-param>
			<name>view-jsp</name>
			<value>/WEB-INF/pages/flex/subscriber/view.jsp</value>
		</init-param>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>VIEW</portlet-mode>
		</supports>
		<supported-locale>en</supported-locale>
		<portlet-preferences>
			<preference>
				<name>eventNamePref</name>
				<value>sampleEvent</value>
			</preference>
			<preference>
				<name>title</name>
				<value>Sample Flex Portlet (Subscriber)</value>
			</preference>
		</portlet-preferences>
	</portlet>
</portlet-app>


So in this example, I am defining two portlets (simple flex wrappers). They use the same JAVA class that I have written. When I deploy this to Liferay, it will add two records to the Portlet Table, one for samples1 and one for samples2, I should then be able to use the PK of the PORTLET Table for my ratings classPK.

I am trying to leverage functionality that is there, without having to customize anything. In essence, to solve my issue I need to get the "ID_" field (PrimaryKey) from the PORTLET Table for each portlet defined in my Portlet.xml. I would think this is available, but I cant seem obtain this data.

Thanks
Blaine
Blaine Boule, modifié il y a 14 années.

RE: Adding Ratings to portles - classPK?

New Member Publications: 15 Date d'inscription: 02/12/09 Publications récentes
Update, I can get a reference to the Portlet Object, but I cant get the PK off of it:


Portlet portlet = PortletLocalServiceUtil.getPortletById((String)request.getAttribute(WebKeys.PORTLET_ID));	
			
if(portlet !=null){
	System.out.println("portlet id:"+portlet.getId());
	System.out.println("plugin id:"+portlet.getPluginId());
	System.out.println("primary key:"+portlet.getPrimaryKey());
}else{
	System.out.println("Temp is null ");
}


In this snippet, I can get the PortletID, the PluginID, but the PrimaryKey call returns 0. Why is this occurring?

Thanks

Blaine
thumbnail
Samir Bhatt, modifié il y a 14 années.

RE: Adding Ratings to portles - classPK?

New Member Publications: 10 Date d'inscription: 26/08/09 Publications récentes
Portlet model is normally not persisted in database until you modify something through plugin configuration functionality in control panel.

So by defaulte Portlet mode is polulated from portlet.xml and then if you override or save the model from plugin configuration tab then a new entry is created in portlet table in the databse.

So from control panel go to Plugin Configuration and then from Portlet Plugins tab locate your portlets and click on it. After that without changing anything click on save. A new entry will be created in portlet table. Then try your code.

Though this is not the right approach, right approach would be to have one model class storing ratings against it.

Regards,

Samir Bhatt
CIGNEX Technologies
Blaine Boule, modifié il y a 14 années.

RE: Adding Ratings to portles - classPK?

New Member Publications: 15 Date d'inscription: 02/12/09 Publications récentes
Ahh, makes sense now. So in reality I need to implement a model for these wrapper portlets and use that PK for ratings.

Thank you for the clarification.

Blaine