Incompatible portlet value of type

[javax.portlet.RenderRequest] resolved to incompatible value of type ..

I encounter this problem during my portlet development and spend quite sometime to figure out the root cause and solutions.

  1. Caused by: java.lang.IllegalStateException:
  2.  
  3. Standard argument type [javax.portlet.RenderRequest] resolved to incompatible value of type [class com.liferay.portlet.ActionRequestImpl]. Consider declaring the argument type in a less specific fashion.
  4.         at org….resolveCommonArgument(HandlerMethodInvoker.java:849)
  5.         at org….resolveHandlerArguments(HandlerMethodInvoker.java:298)
  6.         at org….invokeHandlerMethod(HandlerMethodInvoker.java:151)
  7.         … 176 more
  8. |#]
  9.  
  10. [#|2010-07-16T13:27:44.296+0800|INFO|sun-appserver2.1|javax.enterprise.system.stream.out|_ThreadID=19;_ThreadName=httpSSLWorkerThread-8080-1;|13:27:44,296 ERROR [jsp:164] java.lang.IllegalStateException: Standard argument type [javax.portlet.RenderRequest] resolved to incompatible value of type [class com.liferay.portlet.ActionRequestImpl]. Consider declaring the argument type in a less specific fashion.
  11.         at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:80)
  12.         at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:56)
  13.         at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
  14.         at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
  15.  
  16. |#]



Sample Code

  1.  
  2. @Controller
  3. @RequestMapping("EDIT")
  4. public class ConfigurationController {
  5.           @Autowired private PortletPreferencesService service;
  6.  
  7.            @RenderMapping
  8.            public String doView(RenderRequest request, RenderResponse response) {
  9.                      return "configuration";
  10.            }        
  11.  
  12.            @ActionMapping
  13.             public void doPost(@ModelAttribute(value = "config") PortletPreferences preferences,
  14.                   ActionRequest request, ActionResponse response) {
  15.                  //…do something
  16.             }
  17.  
  18.            @ModelAttribute("config")
  19.            public PortletPreferences getPortletPreferences(RenderRequest request) {
  20.                     ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
  21.                     String portletId = themeDisplay.getPortletDisplay().getId();
  22.                     long plid = themeDisplay.getScopeGroupId();
  23.                     return service.getPortletPreferences(plid, portletId);
  24.            }
  25.  
  26. }
  27.  



Explain:
From the above sample code, it will first load the @ModelAttribute(“config”) before any others method. Therefore, the RenderRequest is still valid object. But once you click the submit or link from your jsp for ActionResponse.

It will load again @ModelAttribute(“config”), but this time the PortletRequest is instance of “Action” type, so spring will throws the exception into console or log file like “[javax.portlet.RenderRequest] resolved to incompatible value of type [class com.liferay.portlet.ActionRequestImpl].”

Workaround :
Remember never apply RenderRequest in your @ModelAttribute directly, you can choose to use @RequestParam(“id”) String id, instead of the RenderRequest to avoid the incompatible error.

You can leave a response, or trackback from your own site.

Leave a Reply

Security Code: