开发者

Liferay: how to save to portlet user information?

开发者 https://www.devze.com 2023-03-27 08:19 出处:网络
I have at the welcome page a weather portlet, and user can configure the portlet and select his city. Is it possible to store user information in the portlet preferences, so that every user has his on

I have at the welcome page a weather portlet, and user can configure the portlet and select his city. Is it possible to store user information in the portlet preferences, so that every user has his one store开发者_运维百科d city? Or what is the standard workflow to store user-portlet information without to develop own (persist) service?

thx


The portlet-preferences are in liferay per default not user specific. That can be modified in liferay-portlet.xml with next lines:

<liferay-portlet-app>
  <portlet>
    <portlet-name>ThePortletWitchUserSpecificPreferences</portlet-name>
    <icon>/icon.png</icon>
    <preferences-unique-per-layout>false</preferences-unique-per-layout>
    <preferences-owned-by-group>false</preferences-owned-by-group>
  </portlet>
...
</liferay-portlet-app>

the two lines <preferences-... and the order are abbreviated.

for more information see: http://rutvijshah.wordpress.com/2009/12/06/user-specific-preferences-in-liferay/


It's not a native function of the PortletPreference : the setValue method allow only a String, unfortunately you can't pass a Map.

However, i see a solution to hardcode it, but it's a little bit ugly...

Long userId = ...... ; 
String userValue = ..... ;

PortletPreferences prefs = request.getPreferences();
prefs.setValue("myConfig-"+userId, myUserVal);
prefs.store();

And for retrieve the data :

String userValue = prefs.getValue("myConfig-"+userId, defaultValue);

This solution will work, but don't do that is you have a big numbers of users.
Portlet Preferences are save in xml in your database, if you have 100k+ users, it will explode :)

If you think this solution is not enough clean, you will have to create your own persistence method with the ServiceBuilder.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号