You can use the PortletPreferences.store() method directly. Behind the scenes, JBoss Portal will save your user preferences (values) in table jbp_user_pref_prop_value (if you want to check with your DB GUI tool).
In your portlet you should:
1. obtain a reference to PortletPreferences:
PortletPreferences portletPrefs = portletRequest.getPreferences();
2. update the desired values of the preferences:
portletPrefs.setValue(...) or portletPrefs.setValues(...)
3. Invoke portletPrefs.store().
I have another question,
If I have a guest user , then how do I save his preferences ?
I have it setup and use portletPrefs.store(), but nothing appears in the database, is there any configuration I am missing.
Below is my code
PortletPreferences pref = request.getPreferences();
pref.setValues(team + PREF_METRIC_LIST, metricsArray);
pref.setValue(team + PREF_ACTIVE_METRIC_LIST, "yes");
Thanks for all the inputs,
could you give a good primary key for a guest user ? if so I can persist it in a database.
The primary key can be "guest" .
I guess PortletPreferences class assumes that there is a current user who
has logged in.
For guest this might not work as guest need not log in but still I might want to store some preferences for him.
Is there a way I can set the user to guest by default and store the preferences for guest ?