Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
X Man
Portlet Preferences
19 de Janeiro de 2012 04:35

X Man

Ranking: Junior Member

Mensagens: 41

Data de entrada: 5 de Janeiro de 2012

Mensagens recentes

I use PortletPreferences class,this code to store preferences in the action(ConfigAction implements ConfigurationAction):
preferences().setValue("greeting", greeting);

,and this code to retrieve the data in the jsp page:
String greeting = preferences.getValue("greeting", "no peferences");
But I dont get the values that I stored it.
How can I use the preferences successfully.
Thank you.
Dave Weitzel
RE: Portlet Preferences
9 de Fevereiro de 2012 20:14

Dave Weitzel

Ranking: Regular Member

Mensagens: 207

Data de entrada: 18 de Novembro de 2009

Mensagens recentes

Are there any errors in your console log or catalina.out file?

I am also having problems using in 6.1 is that the version you are using? I ma be raising a jira ticket tomorrow if I cannot crack it.

to help more perhaps a full snippet of code showing how the preferences were created in the first place.
Sandeep Nair
RE: Portlet Preferences
9 de Fevereiro de 2012 22:49

Sandeep Nair

Ranking: Liferay Legend

Mensagens: 1732

Data de entrada: 5 de Novembro de 2008

Mensagens recentes

If you are using ConfigurationAction retrieve portletPreferences like this in java

1String portletResource = ParamUtil.getString(
2            actionRequest, "portletResource");
4        PortletPreferences preferences =
5            PortletPreferencesFactoryUtil.getPortletSetup(
6                actionRequest, portletResource);
7preferences().setValue("greeting", greeting);

And in jsp use this
 2PortletPreferences preferences = renderRequest.getPreferences();
 4String portletResource = ParamUtil.getString(request, "portletResource");
 6if (Validator.isNotNull(portletResource)) {
 7    preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
 9String greeting = preferences.getValue("greeting", "no peferences");

Ashraf habibi
RE: Portlet Preferences
5 de Março de 2014 21:39

Ashraf habibi

Ranking: Junior Member

Mensagens: 32

Data de entrada: 13 de Maio de 2011

Mensagens recentes


Its old thread, but my reply will helpful to others.

Portlet preferences based on userId
set the value
long companyId=themeDisplay.getCompanyId();
long ownerId=themeDisplay.getUserId();
int ownerType=PortletKeys.PREFS_OWNER_TYPE_USER;

javax.portlet.PortletPreferences preferences = PortalPreferencesLocalServiceUtil.getPreferences(companyId, ownerId, ownerType);

Get the portlet preferences value
preferences.getValue(key, "No Value ");

if you want to set the portlet preferences based on portletId.
Set the value

ThemeDisplay themeDisplay = (ThemeDisplay)resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);
String portletId=themeDisplay.getPortletDisplay().getId();

javax.portlet.PortletPreferences portletSetup =PortletPreferencesFactoryUtil.getLayoutPortletSetup(themeDisplay.getLayout(), portletId);

try {
portletSetup.setValue(key, value);
portletSetup.setValue(key, value);
try {;
} catch (ValidatorException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
System.out.println("value 1.."+portletSetup.getValue(key, "No Value"));
System.out.println("value 2.."+portletSetup.getValue(key, "No Value"));
} catch (ReadOnlyException e) {

Get the Value
portletPrefrence.getValue(key, "No Value");

Hope it will helpful


Participate in the State of Liferay Community 2017. Help the community and even win some prizes!