Fórumok

Setting portlet preferences in theme does not work at all

Stefan Riegel, módosítva 11 év-val korábban

Setting portlet preferences in theme does not work at all

New Member Bejegyzések: 7 Csatlakozás dátuma: 2012.12.30. Legújabb bejegyzések
Hello all,

after spending almost one day without any result, I think it's time to ask in the forum.

I'm working with a fresh current production tomcat bundle (6.1 CE GA2). All I try to do is adding a search portlet at the top of every page. Not very fancy but a very basic thing for web sites. To achieve this, I created a new theme based on classic and added the following code to docroot/_diffs/templates/portal_normal.vm

$velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
$theme.runtime("71_INSTANCE_ab38", "", $velocityPortletPreferences.toString())
$velocityPortletPreferences.reset() 


(Don't wonder about the wrong portlet id. I'm using the navigation portlet just for testing purpose with an instanceable portlet)

The portlet shows up on all pages with borders. OK, I heard about the preference persistence mechanism (written to the database the first time the portlet is created per page). See Embedding a portlet in the theme. I thought "...very complicated work around for such a basic demand..." but worst, nothing works for me. I tried the following without success:

  • Changing the instance identifier (suggested in the Wiki-Article mentioned above)
  • Cleaning the PortletPreferences table in the MySQL Database (DELETE from PortletPreferences;)


At the moment, I have no clue what to try next. Any idea what I'm missing?

Thanks a lot
Stefan
Bradley Wood, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

Stefan Riegel, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

New Member Bejegyzések: 7 Csatlakozás dátuma: 2012.12.30. Legújabb bejegyzések
Bradley Wood:
In the portal_normal.vm of the theme add "$theme.journalContentSearch()"

the zoe-healthcare theme uses it:
https://github.com/liferay/liferay-plugins/blob/master/themes/zoe-healthcare-theme/docroot/_diffs/templates/portal_normal.vm#L42


OK, thanks a lot Bradley. How did You manage to answer even before I pressed the publish button emoticon Yes this works fine for this special use case. But I still wonder what I'm missing. Surely I'll need to include other portlets in the near future. So I really would like to understand an solve this thing already now.
Bradley Wood, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

Stefan Riegel, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

New Member Bejegyzések: 7 Csatlakozás dátuma: 2012.12.30. Legújabb bejegyzések
I would like to come back to my initial problem. Yes the solution from Bradley works fine for the search portlet, but I need to include other portlets into the theme and into templates. I guess that's a really basic demand and I suspect myself doing something wrong or missing some point. So let me ask in a different way:

Did anyone succeed including portlets (and setting preferences) in themes with the latest production version (tomcat bundle 6.1 CE GA2)?

Thanks
Stefan
thumbnail
Ryan Schuhler, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

Junior Member Bejegyzések: 77 Csatlakozás dátuma: 2012.07.06. Legújabb bejegyzések
If you want to add a portlet to a velocity template, like brad did above, you do the following.

If it is a non-instanceable portlet you would use $theme.runtime("31") (31 is the portlet number for the Image Gallery).

If it is an instanceable you would use $theme.runtime("56_INSTANCE_abcd") (56 is the web content portlet number and "abcd" is the random 4 letter code you add to make the portlet instance unique)

For a list of portlet numbers go here: http://www.liferay.com/community/wiki/-/wiki/Main/Portlet+IDs
For a list of instanceable and non-instanceable portlets go here: http://michi-path.blogspot.com/2012/03/list-intanceable-and-non-instanceable.html

Hope this helps, let me know if it is unclear at all.
Stefan Riegel, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

New Member Bejegyzések: 7 Csatlakozás dátuma: 2012.12.30. Legújabb bejegyzések
Hello Ryan,

thank you for your time. Please refer to my initial posting. I'm aware of all you wrote and I think I did understand how to add portlets to themes. The problem is that setting portlet preferences (within the velocity template) simply don't work. I understand that Liferay persists portlet settings the first time portlets are created (per instance if instanciable). Therefor I tried different things like changing the instance ID or clearing the PortletPreferences Table. Nothing seem to work. Always the portlets remain with borders. To be very clear:

See the code from my initial posting. I did include this code in the header section. So the portlet shows up on all pages.

1) Creating a page
2) Nice, empty page including just the portlet
3) The portlet shows up with borders. This should not happen.
4) Changing the portlet setting in the front end (no borders)
5) Now the page looks like i should
6) Creating a new page
7) Again shows up with borders
....

I have no clue what causes this problem. I did start with a new tomcat bundle and a new clear MySQL database. So what's wrong with me? Nobody seem to have the same issue? Could it be a global preference which found some mysterious way into my clean installation? You know, errors mostly happen between the chair and the keyboard ;-)
thumbnail
Ryan Schuhler, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

Junior Member Bejegyzések: 77 Csatlakozás dátuma: 2012.07.06. Legújabb bejegyzések
Hey Stefan,
Sorry about the confusion on my last post, that was my fault. You can make an embedded portlet borderless with the following code:
$velocityPortletPreferences.setValue("portletSetupShowBorders", "true")
$theme.runtime("56_INSTANCE_abcd", "", $velocityPortletPreferences.toString())


However, there is a bug (LPS-27160 i think) which means it lets you set the border initially, but you cannot change it after. This means if you set 56_INSTANCE_abcd to have no borders, if you want to change it then you have to make a new instance of it such as 56_INSTANCE_abcde and set that to have borders. Hope that makes sense.

Let me know if that works for you and if you have any other questions.
Stefan Riegel, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

New Member Bejegyzések: 7 Csatlakozás dátuma: 2012.12.30. Legújabb bejegyzések
Hmmm, don't know. Never managed to include a borderless portlet in themes. Looking to the database tables, preferences are stored per instance id. After changing the instance id, I see show-border set to false, but still displaying the borders. Strange. As I wrote I tried changing the instance id and i cleared completely the portlet preferences database table.

What confuses me most is that very few people seem to have the same issue. For me it's difficult to imagine a real world web site without lots of portlets in themes and templates. Just imagine a side bar with a news list portlet, some content aggregation portlet, navigation portlet, tag list portlet, weather forecast or whatever. Their has to be a lot of developers facing the same problem and doing work arounds.

OK, it's late here. I'll continue tomorrow with a completely new installation, trying to locate the problem and find a work around. Perhaps fiddeling with CSS...don't know yet.

I'll be back emoticon
Stefan
thumbnail
Ryan Schuhler, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

Junior Member Bejegyzések: 77 Csatlakozás dátuma: 2012.07.06. Legújabb bejegyzések
Hmm, ya, I don't quite know what is going on. Both of these threads seemed helpful to me
https://www.liferay.com/community/forums/-/message_boards/message/13099600
http://www.liferay.com/community/forums/-/message_boards/message/12865547

maybe the <use-default-template>false</use-default-template> could be your issue, but yes, people embed portlets all the time so im not quite sure why its not working in your environment. We will see what happens on a fresh install tomorrow.
Stefan Riegel, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

New Member Bejegyzések: 7 Csatlakozás dátuma: 2012.12.30. Legújabb bejegyzések
OK, still the same. Don't know what to do anymore. Before giving up, I'll wait some days. Perhaps someone can

a) confirm this issue
or
b) show me the steps, how to achieve this simple basic task.
Andrea Previati, módosítva 11 év-val korábban

RE: Setting portlet preferences in theme does not work at all

New Member Bejegyzések: 10 Csatlakozás dátuma: 2012.01.11. Legújabb bejegyzések
Stefan Riegel:
Hmmm, don't know. Never managed to include a borderless portlet in themes. Looking to the database tables, preferences are stored per instance id. After changing the instance id, I see show-border set to false, but still displaying the borders. Strange. As I wrote I tried changing the instance id and i cleared completely the portlet preferences database table.


Hi Stefan, hi guys
i just came across an issue similar to yours.
I'm trying to embed a sitemap portlet into a custom theme. Take a look at my Velocity code:


#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
#set($rluuid = $layoutLocalService.getFriendlyURLLayout($group_id, false, "/newpage"))
#set ($locPortletId = "85_INSTANCE_abc")
$velocityPortletPreferences.setValue("root-layout-uuid", $rluuid.getUuid())


This is what i am doing to programmatically set Root Layout .
Ok...now let's print out portlet prefs value:


portlet prefs: $velocityPortletPreferences.toString()


...but if you change (for example) friendly url and redeploy the theme:

- portlet prefs values changes accordingly the new frienldy url
- portlet prefs values in preferences column of PortletPreferences table contains old root-layout-uuid value

After a couple of hours, i tried to change my portlet id from "85_INSTANCE_abc" to "85_INSTANCE_abcd" and it worked perfectly.
So, what about 85_INSTANCE_abc's preferences?
Still there, in PortletPreferences table with different portletPreferencesId and plid:

portletPreferencesId - ownerId - ownerType - plid - portletId
12405 - 0 - 3 - 12310 - 85_INSTANCE_abc
12420 - 0 - 3 - 12406 - 85_INSTANCE_abc
12422 - 0 - 3 - 12406 - 85_INSTANCE_abcd

Finally, i can't understand if this could be a good choice to embed portlets and set preferences: what about "85_INSTANCE_abc" prefs? That portlet no longer exists...
Bye!
thumbnail
Danny Stevens, módosítva 10 év-val korábban

RE: Setting portlet preferences in theme does not work at all

New Member Bejegyzések: 20 Csatlakozás dátuma: 2011.09.15. Legújabb bejegyzések
Hi Folks,

I have exactly the same problem as the OP.

Here is the code from portal normal:

#set ($VOID = $velocityPortletPreferences.setValue('portlet-setup-show-borders', 'false'))
			#set ($instanceId = 'E3j8')
			#set ($myPortletId = "damleveldisplay_WAR_damlevelportlet_INSTANCE_${instanceId}")
			$theme.runtime($myPortletId, '', $velocityPortletPreferences.toString())
			#set ($VOID = $velocityPortletPreferences.reset())


In the database that produces the following value in portlet preferences
<portlet-preferences><preference><name>portlet-setup-show-borders</name><value>false</value></preference></portlet-preferences>


However the actual portlet displayed still shows borders. I can fix it by going to every page, and manually updating the look and feel for every one.

That is obviously not how it is meant to work. It seems that the VM call writes to the DB but the theme portlet does not read its own preferences until you do a save manually.
Sandeep Shinde, módosítva 9 év-val korábban

RE: Setting portlet preferences in theme does not work at all

New Member Bejegyzés: 1 Csatlakozás dátuma: 2011.07.07. Legújabb bejegyzések
Hi Folks,

The preferences seem to be working for me.
First of all the the preference name to set border is "portletSetupShowBorders". There is no hyphen. My code below.


$velocityPortletPreferences.setValue("portletSetupShowBorders","false")
$velocityPortletPreferences.setValue("advancedConfiguration","true")
$velocityPortletPreferences.setValue("searchConfiguration","{'facets': []}")
$theme.runtime("3","",$velocityPortletPreferences.toString())
$velocityPortletPreferences.reset()


To reset the preferences, delete all the entries in the portletpreferences table and clear the database cache from server administration.

The way I see this works is, the search portlet configurations are scoped to the page. So there will be a seperate configuration for search portlet
on every page even if you embed it in theme. But you dont need to set up the configuration manually if you embed the portlet in theme. As you open a page, the configuration for the search portlet for that page gets added automatically. The preferences will be the same that you set in theme You can verify this by looking at the portletpreferences table. There is a new line for every page for portletid 3.