开发者

Liferay portlet not calling correct render method (ignores setRenderParameter)

开发者 https://www.devze.com 2023-01-11 16:14 出处:网络
I have a portlet which has many rendering and action methods: @Controller @RequestMapping(\"VIEW\") public class CartController {

I have a portlet which has many rendering and action methods:

@Controller
@RequestMapping("VIEW")
public class CartController {
  @RenderMapping() // default render method
  public String defaultRender(RenderRequest req, RenderResponse res, Model model) throws PortalException, SystemException {
    ...
  }

  @RenderMapping(params="action=showCustInfo")
  public String showCustInfo(RenderRequest req, RenderResponse res, Model model) throws PortalException, SystemException {
    ...
  }

  @ActionMapping(params="action=acceptCart")
public void acceptCart(ActionRequest req, ActionResponse res, Model model) throws PortalException, SystemException {
    ...
    res.setRenderParameter("action", "showC开发者_如何学GoustInfo");
    ...
  }

In the code above, the method acceptCart sets a render parameter that should cause showCustInfo to be called in rendering phase.

The problem is that the default rendering method gets called every time. What am I missing?


The reason (it seems) was that the action-parameter was not replaced when I commanded

res.setRenderParameter("action", "showCustInfo");

Instead of replacing the value, Spring added this value for the action parameter as follows (pseudo):

// Before:
params['action'] = ['acceptCart'] // all req params in Spring are handled as String arrays..

// After:
params['action'] = ['acceptCart','showCustInfo']

At this point, Spring does not seem to know what to do and calls the default render method. I worked this around by using a different parameter name for the render parameter ('render'). Thus now actions get called by 'action'-parameter and renderers by 'render'-parameter.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号