留言板

Poll Display portlet : how to use same instance?

thumbnail
Paul .,修改在12 年前。

Poll Display portlet : how to use same instance?

Liferay Master 帖子: 522 加入日期: 11-8-29 最近的帖子
I am just begining with Liferay, is there a way to use same question on poll display portlet.
For instance, if I place poll display portlet on different pages and configure it to use same question. Now if I want to change the question I'll have to configure it on all pages. Is there a way so that the configuration is changed everywhere? The other option of changing the question text itself is not workable as if a user already voted to such question, the users is shown voted on the changed text too.
thumbnail
Sandeep Nair,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Hi,

Since they are all having separate portlet instance its not possible technically.

But there is a hack and a way around it, if you wanna try. Basically the idea is to have same instance right. Go to manage page for the page(destination) on which you want same portlet instance(source). There is an option called copy portlets and then drop down to select page from where you want to copy. Select the source page and click save. Now both pages have same instanced portlets. Remove the portlets you dont want and just keep the polls portlet

Regards,
Sandeep
thumbnail
Paul .,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

Liferay Master 帖子: 522 加入日期: 11-8-29 最近的帖子
Hi Sandeep,

Thanks a lot for this input. However I am looking into an alternative. I'll place them in the layout itself using
$processor.processPortlet("59_INSTANCE_abcd")


This works (to the extent of getting the instance Id right , as you mentioned) however, it still doesn't show the selected question. Perhaps it's somewhere dependent on layout / pageid also?
thumbnail
Paul .,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

Liferay Master 帖子: 522 加入日期: 11-8-29 最近的帖子
I checked in the database, it's bound to 'plid' in portletPreferences table
Then I see no other option yet except for doing a database update with preferences.
Any other ideas?
thumbnail
Sandeep Nair,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Is it possible for you to create a portletpreference model listener for update event wherein you search the portletId(the ones having the same instance) and update the preference for each of them.

Regards,
Sandeep
thumbnail
Paul .,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

Liferay Master 帖子: 522 加入日期: 11-8-29 最近的帖子
Thanks Sandeep, I did that and works fine. I am thinking about the overhead that it would add since it will check for all portlets. Also I am looking for a way to clear the cache, as the change isn't reflected.
thumbnail
Sandeep Nair,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

Liferay Legend 帖子: 1744 加入日期: 08-11-6 最近的帖子
Hmm, I agree it will be a performance hit, every time preference is updated. Is it the db cache you are wanting to clear, if so you can use CacheRegistryUtil.clear();

Regards,
sandeep
Hector Leon Garay,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

New Member 帖子: 9 加入日期: 11-7-14 最近的帖子
Hello Paul
I would like to know if you can show me please the way you did to create the portletpreference model listener in order to update the portlet id? I have an idea of what you asked Sandeep, but I don't know where to start

Regards
Hector Leon Garay,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

New Member 帖子: 9 加入日期: 11-7-14 最近的帖子
Somebody can help me please?
thumbnail
Paul .,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

Liferay Master 帖子: 522 加入日期: 11-8-29 最近的帖子
Hi Hector,

Sorry for the late reply. Here is how you can achive this with a properties hook.
You need to create a value.object hook to add a listerner that will be called when preferences are updated, deleted etc.
Check out this post for any help (http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Portal+Hook+Plugins)

value.object.listener.com.liferay.portal.model.PortletPreferences=com.abc.PortletPreferenceListener


This custom listener should
implements ModelListener<portletpreferences> {</portletpreferences>


When the preferences are updated this method will be called so you override it.
public void onAfterUpdate(PortletPreferences model)


You can get the preferences of the model being updated and get the rest of prefernces to be updated using Dyanmic query.
Here is a snippet to achive this.
DynamicQuery query = DynamicQueryFactoryUtil.forClass(PortletPreferences.class, PortalClassLoaderUtil.getClassLoader()).add(PropertyFactoryUtil.forName("portletId").like("59_INSTANCE_%"));
		
		try {
			List<portletpreferences> portletPreferences = PortletPreferencesLocalServiceUtil.dynamicQuery(query);
			for(PortletPreferences portletPreference: portletPreferences){
				try {
					portletPreference.setPreferences(PortletPreferencesLocalServiceUtil.getPortletPreferences(model.getPortletPreferencesId()).getPreferences());
				}</portletpreferences>


Hope it helps.
thumbnail
Dhrutika Parekh,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

Expert 帖子: 435 加入日期: 09-2-9 最近的帖子
Hi,

If you don't require to add polls portlet on same page more than once,then make that portlet non-instanciable.

Regards,
Dhrutika
Hector Leon Garay,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

New Member 帖子: 9 加入日期: 11-7-14 最近的帖子
Hi Dhrutika.
Thanks for your answer, I will try what you said and tell you later, but as you said, I don't need right now to have more than one portlet on the same page, but I need to have the same poll question display on every page on the community site.

Regards

HL
Hector Leon Garay,修改在12 年前。

RE: Poll Display portlet : how to use same instance?

New Member 帖子: 9 加入日期: 11-7-14 最近的帖子
Hi Dhrutika.

Sorry for the delay, the way you told to didn't work, I'm using Paul's way, which I will post later.

Thanks Again

HLG