Wednesday, May 30, 2012

Grails groovy.lang.MissingPropertyException: No such property: portletResponse

Problem:

Using the Grails Porlet plugin, I submitted an action request which would in turn invoke the actionView method of the generated portlet. However I received the following error, when I try to use the auto injected variable 'portletResponse':

groovy.lang.MissingPropertyException: No such property: portletResponse

Discussion:


I decided to dump out all the attributes for the request object as follows:

    def actionView = {
        logger.info("actionView")
        
        
        for (String attrName : request.getAttributeNames()) {
            logger.info("Name="+attrName+"    Value="+request.getAttribute(attrName))
        }
        portletResponse.setRenderParameter("prp-1", "value-1"); // <-- portletResponse is supposed to be auto injected
    }

Then when I viewed the output I saw the following in the logs:

2012-05-30 23:48:28,703 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.servlet.include.request_uri    Value=/apf-portal/Apf/invoke
2012-05-30 23:48:28,703 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.servlet.include.context_path    Value=/apf-portal
2012-05-30 23:48:28,704 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.servlet.include.servlet_path    Value=/Apf
2012-05-30 23:48:28,704 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.servlet.include.path_info    Value=/invoke
2012-05-30 23:48:28,704 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=com.liferay.portal.kernel.servlet.PortletServletConfig    Value=org.apache.catalina.core.StandardWrapperFacade@19a5b51
2012-05-30 23:48:28,704 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=grails.portlet.name    Value=Apf
2012-05-30 23:48:28,705 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=grails.portlet.config    Value=com.liferay.portlet.PortletConfigImpl@1647724
2012-05-30 23:48:28,707 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.portlet.config    Value=com.liferay.portlet.PortletConfigImpl@1647724
2012-05-30 23:48:28,708 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=com.liferay.portal.kernel.servlet.PortletServletResponse    Value=com.liferay.portal.kernel.servlet.StringServletResponse@faa1b4
2012-05-30 23:48:28,708 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=INVOKER_FILTER_URI    Value=/Apf/invoke
2012-05-30 23:48:28,717 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.portlet.response    Value=com.liferay.portlet.ActionResponseImpl@13a1d01
2012-05-30 23:48:28,718 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=PORTLET_ID    Value=Apf_WAR_apfportal
2012-05-30 23:48:28,730 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=com.liferay.portal.kernel.servlet.PortletServletRequest    Value=com.liferay.portal.servlet.NamespaceServletRequest@3858a8
2012-05-30 23:48:28,731 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.portlet.portlet    Value=org.codehaus.grails.portlets.GrailsDispatcherPortlet@9a5b5c
2012-05-30 23:48:28,740 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=WINDOW_STATE    Value=normal
2012-05-30 23:48:28,740 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=org.codehaus.groovy.grails.WEB_REQUEST    Value=ServletWebRequest: uri=/c/portal/layout;client=127.0.0.1;session=ED170D76D6BB5AF372ED336B020604E5;user=2
2012-05-30 23:48:28,754 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.portlet.lifecycle_phase    Value=ACTION_PHASE
2012-05-30 23:48:28,754 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=javax.portlet.request    Value=com.liferay.portlet.ActionRequestImpl@14480c8
2012-05-30 23:48:28,761 [http-bio-8080-exec-104] INFO  portal.ApfPortlet  - Name=com.liferay.portal.kernel.servlet.PortletServletFilterChain    Value=com.liferay.portlet.FilterChainImpl@62fa4e

As you can see, the attributes highlighted in red can give you access to the portletRequest and portletResponse objects.

Solution:

After dumping out the attributes you can now get the PortletRequest and PortletResponse as follows:


        PortletResponse portletResponse = request.getAttribute("javax.portlet.response")
        PortletRequest portletRequest = request.getAttribute("javax.portlet.request")


No comments:

Post a Comment