I'm pretty new to the portlet development and i wonder how to store the preferences per user. I'm using the WebSphere 8.5 Portal Server, Spring 4.3.2 and the RAD v9.5.
At the moment i'm using the PortletPreferences
to store the data in my Controller.java
like this:
@ActionMapping(params = "action=saveUserPref")
public void saveUserSettings(ActionRequest req, @RequestParam("radio") String color) throws ReadOnlyException, ValidatorException, IOException {
PortletPreferences pref = req.getPreferences();
pref.setValue(accountService.getUsername()+"_fontcolor", color);
pref.store();
}
And to get the preferences in my .jsp
like this:
<div style="color:<%=renderRequest.getPreferences().getValue(renderRequest.getPortletSession().getAttribute("username")+"_fontcolor",
"black")%>;">
I read in some posts that this method works, but it isn't the cleanest way to save the user preferences, cause if u have a big ammount of users this will become very slow.
Right now i'm looking for a fast way to save and get the preferences even with a big ammount of users. What are the best practice solutions in the real world?
I have never seen this be a problem for performance even in some of the 100k user range. Portlet preferences should be used for portlet specific preferences, if they are to be shared over more than one portlet, the better place to store them is into a user store like an ldap. If you use ldap portal takes care of the caching for you. You can also use a look aside databas as part of Portal and store user attributes in the db and they come as part of the user object from PUMA.
With portlet preferences I would recommend caching them so you are not having to go the portal layer every time.
At the end though, preferences specific to a portlet, save to portlet preferences, specific to the user, put in a user store like ldap, look aside or something similar like a portlet service that uses its own database.