Planned maintenance is scheduled for the week of June 15th - the exact date and time will be announced soon.
See More Details
Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Unable to read portlet preferences with Spring 2.5
3616598, módosítva 16 év-val korábban
New Member
Bejegyzések: 6
Csatlakozás dátuma: 2009.07.21.
Legújabb bejegyzések
Hi,
I'm trying to read the portlet settings using Spring Portlet MVC 2.5, but so far no luck.
My portlet.xml with preferences is:
The code to read them is:
Somehow the map is always empty and so the values passed as 'default value' are always returned (and not the '123456test' as I was hoping for).
What am I doing wrong?! This problem has cost me all day... and I'm starting to get depressed.
I'm trying to read the portlet settings using Spring Portlet MVC 2.5, but so far no luck.
My portlet.xml with preferences is:
<!--?xml version="1.0" encoding="UTF-8"?-->
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd">
<portlet>
<description>Portlet displaying the user account summary</description>
<portlet-name>user-account-portlet</portlet-name>
<display-name>User account summary</display-name>
<!-- <portlet-class>nl.detelefoongids.oase.portlet.BasePortlet</portlet-class> -->
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/context/baseportlet.xml</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
<portlet-mode>edit</portlet-mode>
</supports>
<supported-locale>en</supported-locale>
<portlet-info>
<title>User account summary</title>
<short-title>User account summary</short-title>
<keywords>base default portlet user account summary</keywords>
</portlet-info>
<portlet-preferences>
<preference>
<name>test</name>
<value>123456test</value>
</preference>
</portlet-preferences>
</portlet>
</portlet-app>
The code to read them is:
package customer.packagename;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping(value = "EDIT")
public class DefaultEditController {
@RequestMapping
public String handleActionRequest(ModelMap model, PortletRequest request) {
PortletPreferences preferences = (PortletPreferences)request.getPreferences();
System.out.println("Action: Preferences = " + preferences);
System.out.println("Action: Preferences map leeg? = "+ preferences.getMap().isEmpty());
System.out.println("Action: Preferences - test = " + preferences.getValue("test", "default value"));
System.out.println("Action: Preferences - presentation = " + preferences.getValues("presentation", new String[]{"1"}).length);
// model.addAttribute("test", preferences.getValue("test", "not set!"));
return "edit";
}
}
Somehow the map is always empty and so the values passed as 'default value' are always returned (and not the '123456test' as I was hoping for).
What am I doing wrong?! This problem has cost me all day... and I'm starting to get depressed.
3616598, módosítva 16 év-val korábban
New Member
Bejegyzések: 6
Csatlakozás dátuma: 2009.07.21.
Legújabb bejegyzések
Got it!
Preferences are read when the portlet is put on the page. Since the preferences were added after the portlet was put on a page, they were not available.
Removing the portlet and putting a fresh instance on a page resolved my problem.
Thanks for reading. :-)
Preferences are read when the portlet is put on the page. Since the preferences were added after the portlet was put on a page, they were not available.
Removing the portlet and putting a fresh instance on a page resolved my problem.
Thanks for reading. :-)
Community
Company
Feedback