Liferay+Spring:@ModelAttribute在带有url参数的渲染方法中



我想制作带有过滤器和搜索结果的portlet。过滤器必须在get方法中发送。我正在使用spring-annotation@ModelAttribute作为过滤器。但过滤器中的所有属性都为null,因为可能会为_[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时,在过滤器属性中,text是test,但我只想在url中使用text参数。

知道它是怎么做的吗?

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

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

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

如果url中有"text"参数,则可以使用,而如果@ModelAttribute

@RequestParam("text") String text

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

@RequestParam String text

另外请注意,@RequestParam,如上所示,默认情况下会使参数成为必需参数。如果不需要使用

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

您的渲染方法应该(也)具有@RenderMapping注释。

最新更新