【问题标题】:Liferay + Spring : @ModelAttribute in render method with url parametersLiferay + Spring:带有url参数的render方法中的@ModelAttribute
【发布时间】:2013-12-23 23:48:46
【问题描述】:

我想制作带有过滤器和搜索结果的 portlet。过滤器必须在 get 方法中发送。 我正在使用弹簧注释@ModelAttribute 进行过滤。但是过滤器中的所有属性都是空的,因为 liferay 使用 _[PORTLET_NAME]_WAR_[WAR_NAME] 等 url 参数的前缀。 我使用 actionRequest 并通过 post 方法发送过滤器并且它工作正常,但我需要 url 中的参数。

控制器中的方法:

@RequestMapping
public String view(@ModelAttribute("filter") ProcessSearchFilter filter, RenderRequest request, Model model)

当参数名称为 _processSearch_WAR_portlets_text=test 时,过滤器属性中的文本为 test,但我只想在 url 中使用文本参数。

知道它是怎么做的吗?

【问题讨论】:

    标签: java spring liferay


    【解决方案1】:

    Liferay 6.2 开始,必须为视图页面上的字段声明名称空间前缀。如果您没有从提交的表单中收到任何值,请尝试像这样设置前缀

    <input type="text" name="<portlet:namespace />inputTextName" />
    

    或更改您的 portlet 的设置,使其不需要它们。在 liferay-portlet.xml 中,将所选 portlet 的 requires-namespaced-parameters 标记设置为 false

    【讨论】:

      【解决方案2】:

      如果你在 url 中有 "text" 参数,那么你可以使用,而不是 @ModelAttribute

      @RequestParam("text") String text
      

      或者,如果参数变量名与参数名相同

      @RequestParam String text
      

      还要注意@RequestParam,如上所示,默认情况下需要参数。如果这不是想要的使用

      @RequestParam(value = "text", required = false) String text
      

      你的渲染方法应该(也)有@RenderMapping注解。

      【讨论】:

        猜你喜欢
        • 2020-01-30
        • 2014-04-23
        • 2021-04-12
        • 2014-09-20
        • 2011-10-15
        • 1970-01-01
        • 2015-06-08
        • 2018-12-22
        相关资源
        最近更新 更多