0

I have a theme realized in Liferay. I have a form portlet on the control panel that the user can fill. Depending on the values inserted in the portlet the theme homepage should appear differently.

I was thinking to use something like that but it doesn't work:

#set($typeLong = $portal.getClass().forName('java.lang.Long').getField('TYPE').staticValue)
#set($personalOptions = $portal.getClass().forName("com.mypackage.utils.Configuration").getMethod("getStrings", $typeLong).invoke(null,$scopeGroupId))

where my "getStrings" is a method defined in the "Configuration" class with input a long and a String[] array return.

Any advices?

user73793
  • 151
  • 8

1 Answers1

1

Don't go along that route. It might work in a few circumstances but it's nothing more than a crazy hack. It will break in some kinds of conditions.

Keep in mind that your theme might be in a different classloader than your portlet - thus your com.mypackage.utils.Configuration class might not even be available.

IMHO showing personal content is a piece of business logic that's best encapsulated in a portlet - and you can embed portlets in a theme so that they're automatically shown on each page. The portlet can also be implemented to not show anything if it doesn't need to. Add fancy CSS to your theme (for exactly this portlet) to make it appear special. For example like Liferay's dockbar or chat portlet: Both are portlets with fancy CSS: They don't look like portlets, but indeed they are. And they're automatically embedded in every page.

Separate concerns, have actual content and personal data in portlets. Your future maintainers will thank you (even if it's only the future you who will thank you)

Olaf Kock
  • 46,930
  • 8
  • 59
  • 90
  • Yes I understood your issue but still didn't understand the alternative you propose for my actual concern. – user73793 Feb 24 '15 at 17:08
  • Please describe what kind of personal information you'd like to show - then it will be easier to suggest an alternative implementation. – Olaf Kock Feb 25 '15 at 10:11
  • I already solved the issue...my problem was that I missed velocity.engine.restricted.classes= in portal properties – user73793 Feb 25 '15 at 10:26