Search code examples
javahtmljspliferayportlet

jsp losing attribute passed from the backend


I've got a problem in my project. This is a part of my code, which I think is causing the problem.

    @Override
public void dLMSreceiveInput(ActionRequest actionRequest,
        ActionResponse actionResponse) throws ParseException {

    dynamicLogic = actionRequest.getParameter("setlogic");
    logic = actionRequest.getParameter("outerlogic");
    PortletPreferences prefs = actionRequest.getPreferences();
    dLMSSendRender(dLMSCreateQuery(actionRequest), actionResponse,
            actionRequest);
}

public void dLMSSendRender(List<DLFileEntry> foundFiles,
        ActionResponse actionResponse, ActionRequest actionRequest) {
    if (foundFiles.size() == 0) {
        actionResponse.setRenderParameter("jspPage", "/notFound.jsp");
    } else {
        actionRequest.setAttribute("DLMSFoundFiles", foundFiles);
        actionRequest.setAttribute("urls", fileURL(themeDisplay, foundFiles));
        actionResponse.setRenderParameter("jspPage", "/edit.jsp");
    }
}

... I think there is a problem in redirecting by setting a RenderParameter.

actionResponse.setRenderParameter("jspPage", "/edit.jsp");

The content renders, but when I do an action in another portlet it disappears. Any ideas how to redirect correctly, when I want to show my results? Thank you.


Solution

  • SOLVED. By saving session attribute, not actionRequest attribute.

        HttpServletRequest request = PortalUtil.getHttpServletRequest(actionRequest);
    HttpSession session = request.getSession();
    session.setAttribute("DLMSFoundFiles", foundFiles);
    session.setAttribute("urls",fileDownloadURL(themeDisplay, foundFiles));
    actionResponse.setRenderParameter("jspPage", "/edit.jsp");
    

    in jsp

     List<DLFileEntry> DLMSFoundFiles1 = (List<DLFileEntry>) session.getAttribute("DLMSFoundFiles");
     Map<String, String> urls = (Map<String, String>) session.getAttribute("urls");
    

    leaving it here for further use.