Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: attribute not passing from action to render phase | liferay 7.4
when I attribute in action phase is not passing to render phase. Below is the code snippet I used
action class:
actionRequest.setAttribute("key", "value");
render method:
renderRequest.getAttribute("key");
Is the way changed in Liferay 7.4 to accomplish the same
This question also came up internally, and a colleague referenced the portlet spec:
14.1.2.5 Action-scoped Request Attributes
The Java Portlet Specification follows a model of separating concerns into different request processing phases, such as the action phase, the event phase, and the render phase. This provides a clean separation of the action semantics from the rendering of the content, however, it may create some issues with servlet-based applications that don’t follow this strict Model View-Controller pattern. Such applications in some cases assume that attributes that they set in the action phase will be accessible again when starting the rendering. The Java Portlet Specification provides the render parameters for such use cases, but some applications need to transport complex objects instead of strings. For such use cases the Java Portlet Specification provides the action-scoped request attributes as container runtime option with the intent to provide portlets with these request attributes until a new action occurs. Section 8.4.4 Runtime Option javax.portlet actionScopedRequestAttributes on page 51 describes this option in more detail.
And 8.4.4 contains this info:
Portlets that want to leverage the action-scoped request attributes must to set the container runtime
option javax.portlet.actionScopedRequestAttributes to true, default is
false. In addition, the portlet may provide a value called numberOfCachedScopes where the
following value element must be a positive number indicating the number of scopes the portlets
wants to have cached by the portlet container. This value is a hint to the portlet container that
the portlet container may not be able to honor because of resource constraints. The order of the
values in the portlet deployment descriptor must be true, numberOfCachedScopes, <number
of cached scopes>
...and it seems that another (more brute force) workaround goes through the original HttpServletRequest.
Powered by Liferay™