PDA

View Full Version : Problems with PortletConfig parameters


zman
Feb 13th, 2006, 06:34 AM
Hi

I am having problems with trying to add an init-param to portlet.xml and access it in a controller. Below is my portlet.xml
<portlet>
<portlet-name>Search</portlet-name> <portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/context/portlet/search.xml</value>
</init-param>
<init-param>
<name>refreshResults</name>
<value>5000</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Search</title>
</portlet-info>
</portlet>
</portlet-app>

and my controller

public class SummaryController extends AbstractController implements PortletConfigAware {
public void setPortletConfig(PortletConfig portletConfig)
{
this.portletConfig = portletConfig;
}
protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception
{
// readRefreshInterval(request);

try { System.err.println("HERE1="+portletConfig.getInitParameter("refreshResults"));
} catch (Exception e) {}
return new ModelAndView("summary", "model",model);
}
}

The portlet fails to render and the error I am getting is:
org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'refreshResults' of bean class [org.springframework.web.portlet.DispatcherPortlet]: Bean property 'refreshResults' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Can you please help. Thanks

dsklyut
Feb 13th, 2006, 11:13 PM
Your portlet class should extend DispatcherPortlet and provide a setter for the refreshResults property.

What version of the Spring 2.0 are you using. M1 had a problem where this exception will be thrown - it was fixed in M2 (I think) - now it should ignore the init-param that do not have a setter.

Dmitry

zman
Feb 14th, 2006, 04:51 AM
Thanks for the reply

I provided a setter for the refreshResults property like so

public class SummaryController extends DispatcherPortlet implements PortletConfigAware
{
private String refreshResults;
public void setRefreshResults(String refreshResults)
{
this.refreshResults = refreshResults;
}

// other methods ...
}

The error I am getting is
org.springframework.beans.NotWritablePropertyExcep tion: Invalid property 'refreshResults' of bean class [org.springframework.web.portlet.DispatcherPortlet]: Bean property 'refreshResults' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

I am using spring 2.0 m1

dsklyut
Feb 14th, 2006, 09:23 AM
See bolded text below.

Dmtiry

<portlet>
<portlet-name>Search</portlet-name>
<portlet-class>your.package.SummaryController</portlet-class>
<init-param>
<name>contextConfigLocation</name>
<value>/WEB-INF/context/portlet/search.xml</value>
</init-param>
<init-param>
<name>refreshResults</name>
<value>5000</value>
</init-param>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Search</title>
</portlet-info>
</portlet>
</portlet-app>

zman
Feb 14th, 2006, 11:40 AM
I think the portlet.xml file is correct certainly according to the spring portlet tutorial which uses the same format as my portlet.xml. I have other controllers in the same portlet. There must be another way.

dsklyut
Feb 14th, 2006, 11:59 AM
You created a subclass with a setter for a property but using a superclass as a portlet. How do you think spring or java will be able to know that a subclass of the declared portlet has a property with the name specified in the init-parameter and set it?

So by changing the <portlet-class> to the subclass of the DispatcherPortlet that has a setter method for the property that you are trying to use internally it will get set and every one will be very happy :)

On the same wave - upgrade to M2 that will help in your exception. PortletConfigAware should be used on your Controller object not your Portlets.

Dmitry