Reputation: 6629
I have a portlet which is configured as preferences-commpany-wide, so same preferences are shared between everyone
Now I would like to put a default value on those preferences, so this code should be needed only first execution on whole lifecycle. That is why I believe init() method is the best option for setting this default values in case they are not already set before.
How can I retrieve PortletPreferences object from there?
EDIT I am looking for portletContext and portletConfig retrievable from GenericPortlet but no luck so far
Upvotes: 0
Views: 1200
Reputation: 48057
If you really never ever ever ever change the values, so that it's fine to initialize them once and keep them until you restart your server, I'd hardcode them in your portlet.
If there is a slight chance that the config might change (if only initially, after adding a portlet to a page), read them when you need them. And provide defaults in portlet.xml:
<portlet>
<portlet-name>my-portlet</portlet-name>
<portlet-class>
com.example.MyPortlet
</portlet-class>
<portlet-preferences>
<preference>
<name>my-first-pref</name>
<value>some default value</value>
</preference>
</portlet-preferences>
</portlet>
Remember: if you ever change the portlet prefs, you'd have to restart the server in order to activate them.
If you happen to worry about performance for fetching the preferences: Measure if there's an impact, post the numbers. My bet is that you can gain a lot more performance in other places. And if you absolutely can't gain performance in other places: Congratulations, you have a well tuned system.
Upvotes: 1