renderRequest getAttribute in jsp does not update as in doView in portlet

Eva Sciacca, modified 12 Years ago. New Member Posts: 3 Join Date: 11/21/12 Recent Posts
Dear all,

I am trying to send dynamic String values from the doView method into the view.jsp. This is the code in doView:


public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
        System.out.println("doView()...");        
        request.setAttribute("test", Math.random());            
        System.out.println(request.getAttribute("test"));
        response.setContentType("text/html");        
        PortletRequestDispatcher dispatcher =
        getPortletContext().getRequestDispatcher("/WEB-INF/jsp/GraphEditorPortlet_view.jsp");
        dispatcher.include(request, response);
    }


And this is how I get it from the GraphEditorPortlet_view.jsp


<%=renderRequest.getAttribute("test") %>


But, everytime I do a post and a doView I always get the same number even if it get printed changed in the doView method.

Any hints?

Kind regards,

Eva.
thumbnail
Mayur Patel, modified 12 Years ago. Expert Posts: 358 Join Date: 11/17/10 Recent Posts
Hi Eva,

It should work. I am attaching a small portlet called AttributePortlet in which i have set attribute in doView and reading the same in view.jsp.

And I would suggest you to use MVCPortlet so that you dont have to worry about dispatching and stuff.

Thanks.
Eva Sciacca, modified 12 Years ago. New Member Posts: 3 Join Date: 11/21/12 Recent Posts
Dear Mayur,

thank you for your reply. In my case the static attribute setting is working but it is not getting updated when doView() method is re-called after a POST call. I don't think moving to MVCPortlet would solve the issue.

Any other hints?

Kind regards,

Eva.