What is the difference between fetching attributes from these implicit objects:
renderRequest.getAttribute("myVar")
actionRequest.getAttribute("myVar")
request.getAttribute("myVar")
Why are they all allowed?
I mean you usually store attribute in actionRequest or renderRequest object but you can get it in request implicit object, why?
What is the correct approach?
How is it possible to get an action object in view time?
Does not it violate the action-render renderParams passing mechanism?
Why are actionRequest/response available as implicit object if they throw NullPointerException when trying to use them in JSP?
Finally when is it useful to store an attribute in the request (PortalUtil.getOriginalServletRequest)?
What is the correct approach for accessing request attributes?
In portlets, the correct approach is to only interact with the
renderRequestfor retrieving parameter values and for getting or setting request attributes (in JSPs or the portlet class).renderResponsecan be used to create new Portlet URLs.Why can you get request attributes from the
requestobject as well?requestis anHttpServletRequestandrenderRequestis aPortletRequest. However, Liferay implementedrequestas a wrapper ofHttpServletRequestin such way that, e.g. for accessing request attributes, it will fallback to thePortletRequestif it doesn’t find the attribute in the actualHttpServletRequest.What’s the use of
actionRequestandactionResponseat view time?Like you say, if you follow the principles of MVC, you will only use the JSP for view logic. If you check the
DefineObjectsTagfrom Liferay, you can see that all thesexxxRequestandxxxResponseobjects are only set if the portlet is in the right lifecycle. Because, normally, you’re in the RENDER_PHASE when executing the JSP logic, onlyrenderRequestandrenderResponsewill be not-null.When is it useful to store an attribute in the
request?It doesn’t really make sense to store attributes in the
HttpServletRequestif you’re working with portlets. On the other hand, inside a servlet (filter) you could add attributes that can then be retrieved from portlets by usingrequest.getAttribute("xxx").