Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Stefan Riegel
Setting portlet preferences in theme does not work at all
14. Februar 2013 15:42
Antwort

Stefan Riegel

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 30. Dezember 2012

Neue Beiträge

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

1$velocityPortletPreferences.setValue("portlet-setup-show-borders", "false")
2$theme.runtime("71_INSTANCE_ab38", "", $velocityPortletPreferences.toString())
3$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:

  1. Changing the instance identifier (suggested in the Wiki-Article mentioned above)
  2. 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
Anonym
RE: Setting portlet preferences in theme does not work at all
14. Februar 2013 15:32
Antwort

Anonym

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
Stefan Riegel
RE: Setting portlet preferences in theme does not work at all
14. Februar 2013 15:52
Antwort

Stefan Riegel

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 30. Dezember 2012

Neue Beiträge

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.
Anonym
RE: Setting portlet preferences in theme does not work at all
14. Februar 2013 16:10
Antwort

Anonym

I subscribe to the theme category in the forums.
Stefan Riegel
RE: Setting portlet preferences in theme does not work at all
17. Februar 2013 14:31
Antwort

Stefan Riegel

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 30. Dezember 2012

Neue Beiträge

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
Ryan Schuhler
RE: Setting portlet preferences in theme does not work at all
19. Februar 2013 09:54
Antwort

Ryan Schuhler

LIFERAY STAFF

Rang: Junior Member

Nachrichten: 77

Eintrittsdatum: 5. Juli 2012

Neue Beiträge

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
RE: Setting portlet preferences in theme does not work at all
19. Februar 2013 13:15
Antwort

Stefan Riegel

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 30. Dezember 2012

Neue Beiträge

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 ;-)
Ryan Schuhler
RE: Setting portlet preferences in theme does not work at all
19. Februar 2013 14:21
Antwort

Ryan Schuhler

LIFERAY STAFF

Rang: Junior Member

Nachrichten: 77

Eintrittsdatum: 5. Juli 2012

Neue Beiträge

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:
1$velocityPortletPreferences.setValue("portletSetupShowBorders", "true")
2$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
RE: Setting portlet preferences in theme does not work at all
19. Februar 2013 15:51
Antwort

Stefan Riegel

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 30. Dezember 2012

Neue Beiträge

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
Ryan Schuhler
RE: Setting portlet preferences in theme does not work at all
19. Februar 2013 16:13
Antwort

Ryan Schuhler

LIFERAY STAFF

Rang: Junior Member

Nachrichten: 77

Eintrittsdatum: 5. Juli 2012

Neue Beiträge

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
RE: Setting portlet preferences in theme does not work at all
20. Februar 2013 15:00
Antwort

Stefan Riegel

Rang: New Member

Nachrichten: 7

Eintrittsdatum: 30. Dezember 2012

Neue Beiträge

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
RE: Setting portlet preferences in theme does not work at all
2. April 2013 13:50
Antwort

Andrea Previati

Rang: New Member

Nachrichten: 10

Eintrittsdatum: 11. Januar 2012

Neue Beiträge

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:

1
2#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))
3#set($rluuid = $layoutLocalService.getFriendlyURLLayout($group_id, false, "/newpage"))
4#set ($locPortletId = "85_INSTANCE_abc")
5$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:

1
2portlet 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!
Danny Stevens
RE: Setting portlet preferences in theme does not work at all
10. April 2014 20:03
Antwort

Danny Stevens

Rang: New Member

Nachrichten: 20

Eintrittsdatum: 14. September 2011

Neue Beiträge

Hi Folks,

I have exactly the same problem as the OP.

Here is the code from portal normal:

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


In the database that produces the following value in portlet preferences
1<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
RE: Setting portlet preferences in theme does not work at all
7. Mai 2014 06:39
Antwort

Sandeep Shinde

Rang: New Member

Nachrichten: 1

Eintrittsdatum: 7. Juli 2011

Neue Beiträge

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.

1
2$velocityPortletPreferences.setValue("portletSetupShowBorders","false")
3$velocityPortletPreferences.setValue("advancedConfiguration","true")
4$velocityPortletPreferences.setValue("searchConfiguration","{'facets': []}")
5$theme.runtime("3","",$velocityPortletPreferences.toString())
6$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.