Passing object list from the action to the render phase

一曲冷凌霜 提交于 2019-12-05 21:03:47
d-man

Add ActionRequest request object into your method signature like as following and add objects as attribute

@ActionMapping(params = "doAction=searchDeviceResults")
public void searchResults(@ModelAttribute(value = "searchForm") SearchForm searchForm,
                          BindingResult bindingResult, 
                          ActionRequest request, 
                          ActionResponse response, 
                          SessionStatus sessionStatus) {

    searchFormValidator.validate(searchForm, bindingResult);

    if (!bindingResult.hasErrors()) {
        response.setRenderParameter("doAction", "showDeviceResults");
        sessionStatus.setComplete();    
        List<AccountDetail> accList = accountService.getAccountDetail(adp);
        request.setAttribute("accountList", accList); // here we go
    }

}

Another important thing is to add below config tags in portlet.xml so without getting and putting again into render method your request attribute will be available on the JSP.

<container-runtime-option>
    <name>javax.portlet.actionScopedRequestAttributes</name>
    <value>true</value>
</container-runtime-option>
<container-runtime-option>
    <name>javax.portlet.renderHeaders</name>
    <value>true</value>
</container-runtime-option>
<container-runtime-option>
    <name>javax.portlet.escapeXml</name>
    <value>false</value>
</container-runtime-option>

Let me know if any issue occurs.

You could try to use JSR 286 Action-scoped Request Attributes. See http://www.theserverside.com/news/1363818/JSR-286-Portlets-Action-scoped-Request-Attributes.

Also, it might have been a typo but annotate your doAction with @ActionMapping(params = ACTION_MYACTION)

I've found the answer!

I need to use

PortletUtils.setSessionAttribute(actionrequest, "mylist", mylist);

instead of the actionresponse.setRenderParameter.

It works!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!