Tags:
create new tag
, view all tags
-- PedroRio - 2013-11-12

PreferenceStore

If you need to save values in the database (but they don't fall into any XEO Model of your application and are more like preferences) you can use the PreferenceStore to do that.

A Preference is nothing more than a key/value store where you can save values persistently, under different types.

There are four different types of Preferences:

  • System (System wide preference)
  • Profile (Per-profile preference)
  • User (Per-user preference)
  • UserInProfile (Per User/Profile)
To create/load a preference you need to get the PreferencesManager like the following:
PreferencesManager manager = boApplication.getXEO().getPreferencesManager();

Once you have a PreferencesManager instance you can create the 4 types of preferences using:

Preference p = manager.getSystemPreference(String name)
Preference p = manager.getProfilePreference(String name, String profile)
Preference p = manager.getUserPreference(String name, String username)
Preference p = manager.getUserInProfilePreference(String name, String username, String profilename)

Each of these methods have a corresponding method which adds an additional parameter named "CustomContext" which basically gives a custom context to the preference (othewise it has no context)

Once you have a preference instance, you can set values like the following:

p.setString(key,value);
p.setBoolean(key,value);
p.setLong(key,value);


and the corresponding:

String value = p.getString(key);
Boolean bolValue = p.getBoolean(key);
Long longValue = p.getLong(key);

In the end, save the preference

p.savePreference();

_


Topic revision: r2 - 2013-11-13 - PedroRio
 

No permission to view TWiki.WebTopBar

This site is powered by the TWiki collaboration platform Powered by Perl

No permission to view TWiki.WebBottomBar