Portlet Preferences

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.

    PortletPreferences preferences = actionRequest.getPreferences();
    String myPreferences = preferences.getValue("preferenceName", "default");

Saving portlet preferences

Preferences may only be saved during an ActionRequest.

    PortletPreferences preferences = actionRequest.getPreferences();
    preferences.setValue("preferenceName", "preferenceValue");
    preferences.store();

Choosing a preference persistence mechanism

PortletPreferences

PROS

Cons

  • Easy setup, no configuration, convenient
  • Standardized, (JSR-168)
  • Great for saving a small number of values
  • Low footprint (no extra libraries, jars)
  • Can be difficult to manage with a large number of preferences
  • Only stores and retrieves String values
  • Implementation may be different on different containers
  • Hard to maintain relationships between values if they exist

Custom Preferences (Database, webservice, etc.)

PROS

Cons

  • Can manage limitless preferences, large or small
  • Can store and retrieve any object type
  • Can easily maintain relationships (e.g. inheritance between groups, users, multiple instances)
  • Generally requires custom persistance design & development
  • Requires configuration and setup on the users and developers part
  • Larger footprint (may require extra libraries, jars)
  • Depending on the technology used, may not work on all databases (unsupported operations)