掲示板
Portlet Preferences
Hello.
I use PortletPreferences class,this code to store preferences in the action(ConfigAction implements ConfigurationAction):
preferences().setValue("greeting", greeting);
preferences().store();
,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.
I use PortletPreferences class,this code to store preferences in the action(ConfigAction implements ConfigurationAction):
preferences().setValue("greeting", greeting);
preferences().store();
,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.
12年前 に Dave Weitzel によって更新されました。
RE: Portlet Preferences
Regular Member 投稿: 208 参加年月日: 09/11/18 最新の投稿
Are there any errors in your console log or catalina.out file?
I am also having problems using preferences.store() 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.
I am also having problems using preferences.store() 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.
10年前 に Ashraf habibi によって更新されました。
RE: Portlet Preferences
Junior Member 投稿: 32 参加年月日: 11/05/13 最新の投稿
Hi
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);
preferences.setValue(key,value);
preferences.setValue(key,value);
preferences.store();
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 {
portletSetup.store();
} catch (ValidatorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("value 1.."+portletSetup.getValue(key, "No Value"));
System.out.println("value 2.."+portletSetup.getValue(key, "No Value"));
} catch (ReadOnlyException e) {
e.printStackTrace();
}
Get the Value
portletPrefrence.getValue(key, "No Value");
Hope it will helpful
Thanks,
Ashraf
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);
preferences.setValue(key,value);
preferences.setValue(key,value);
preferences.store();
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 {
portletSetup.store();
} catch (ValidatorException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("value 1.."+portletSetup.getValue(key, "No Value"));
System.out.println("value 2.."+portletSetup.getValue(key, "No Value"));
} catch (ReadOnlyException e) {
e.printStackTrace();
}
Get the Value
portletPrefrence.getValue(key, "No Value");
Hope it will helpful
Thanks,
Ashraf
12年前 に Sandeep Nair によって更新されました。
RE: Portlet Preferences
Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
If you are using ConfigurationAction retrieve portletPreferences like this in java
And in jsp use this
Regards,
Sandeep
String portletResource = ParamUtil.getString(
actionRequest, "portletResource");
PortletPreferences preferences =
PortletPreferencesFactoryUtil.getPortletSetup(
actionRequest, portletResource);
preferences().setValue("greeting", greeting);
preferences().store();
And in jsp use this
PortletPreferences preferences = renderRequest.getPreferences();
String portletResource = ParamUtil.getString(request, "portletResource");
if (Validator.isNotNull(portletResource)) {
preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
}
String greeting = preferences.getValue("greeting", "no peferences");
Regards,
Sandeep