Liferay portlet 未调用正确的渲染方法(忽略 setRenderParameter)

发布于 2024-09-14 05:21:18 字数 856 浏览 2 评论 0原文

我有一个包含许多呈现和操作方法的 portlet:

@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", "showCustInfo");
    ...
  }

在上面的代码中,方法 acceptCart 设置一个呈现参数,该参数应导致在呈现阶段调用 showCustInfo

问题是每次都会调用默认渲染方法。我缺少什么?

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", "showCustInfo");
    ...
  }

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的心境我的脸 2024-09-21 05:21:18

原因(看起来)是当我命令时 action 参数没有被替换

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

Spring 没有替换该值,而是为 action 参数添加了这个值,如下(伪):

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

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

此时,Spring似乎不知道该怎么做并调用默认的渲染方法。 我通过为渲染参数使用不同的参数名称(“render”)来解决这个问题。因此,现在动作由“action”参数调用,渲染器由“render”参数调用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文