This page is intended to capture discussion related to appropriate strategies to store preferences in a portal environment.
PortletPreferences
...
width | 50% |
---|
PROS
PortletPreferences
The JSR-168 Portlet Preferences API can be used to manage simple String-based preferences for a portlet. Preferences saved via Config mode will be set for all instances of that uPortal portlet definition. Preferences saved via Edit or View modes will be instance-specific.
Querying portlet preferences
Preferences may be queried during either a RenderRequest or ActionRequest.
Code Block | ||||
---|---|---|---|---|
| ||||
PortletPreferences preferences = actionRequest.getPreferences();
String myPreferences = preferences.getValue("preferenceName", "default");
|
Saving portlet preferences
Preferences may only be saved during an ActionRequest.
Code Block | ||||
---|---|---|---|---|
| ||||
PortletPreferences preferences = actionRequest.getPreferences();
preferences.setValue("preferenceName", "preferenceValue");
preferences.store();
|
Choosing a preference persistence mechanism
PortletPreferences
PROS | Cons |
---|---|
|
...
width | 50% |
---|
...
|
Custom Preferences (Database, webservice, etc.)
...
width | 50% |
---|
...
PROS | Cons |
---|---|
|
...
CONS
|
...
PortletConfig
PortletConfig is probably also worth a mention here – though actual patterns between when to use it versus PortletPreferences has been hazy. JSR-286 has somewhat clarified the distinction, noting that PortletConfig settings are generally those settings made by an administrator that are not intended to be end-user over-rideable, or maybe even end-user visible.
...