Note that there are some explanatory texts on larger screens.

plurals
  1. POPortlet: Forward a ResourceRequest to show the full portal
    primarykey
    data
    text
    <p>my intention is to process a ResourceRequest that serves a resource (A dinamically generated PDF). If something goes wrong generating this file, the whole portal with a failure message in the portlet should be rendered.</p> <p>Is it possible to forward a ResourceRequest to a request that renders the complete portal? I am also considering a redirect, but I will like to be able to pass some attributes/parameters along.</p> <p>I hope I explained my problem clear enough. Thank you. </p> <p>Related/Duplicate: <a href="https://stackoverflow.com/questions/17870593/how-to-make-the-resourceresponse-to-forward-the-request-to-error-page-in-liferay">How to make the ResourceResponse to forward the request to error page in liferay portlet</a></p> <h1>Example</h1> <p>This is an example that works and does something similar to what I want to achieve. I uses the utility class <code>SessionErrors</code> of Liferay: The <code>serveResource()</code> saves an object in the session and does a redirection to a render URL. The <code>doView()</code> method is called during the subsequent request and can read the contents saved in the session.</p> <pre class="lang-java prettyprint-override"><code>import com.liferay.portal.kernel.servlet.SessionErrors; import javax.portlet.GenericPortlet; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; import javax.portlet.ResourceRequest; import javax.portlet.ResourceResponse; import javax.portlet.PortletException; import javax.portlet.PortletException; import javax.portlet.PortletRequestDispatcher; public class ResourceRequestForwardPortlet extends GenericPortlet { public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException, IOException { SessionErrors.add(resourceRequest, "resourcerequest.error", "ERROR " + errorText); resourceResponse.setProperty(ResourceResponse.HTTP_STATUS_CODE, "302"); resourceResponse.addProperty("Location", resourceResponse.createRenderURL().toString()); } public void doView(RenderRequest renderRequest, RenderResponse renderResponse) throws IOException, PortletException { String error = (String)SessionErrors.get(renderRequest, "resourcerequest.error"); SessionErrors.clear(renderRequest); renderRequest.setAttribute("errorMsg", error); PortletRequestDispatcher portletRequestDispatcher = getPortletContext().getRequestDispatcher("view.jsp"); include(viewTemplate, renderRequest, renderResponse); portletRequestDispatcher.include(renderRequest, renderResponse); } } </code></pre> <p>What I want to achieve is the same, but preventing the browser from doing two requests. For that, I would like to do a forward and I should write the error message as a request attribute. </p> <p>I uploaded a project with this example to GitHub: <a href="https://github.com/adrianrm/poc-forward-portlet/tree/master/src/main/java/arm/requestforward" rel="nofollow noreferrer">https://github.com/adrianrm/poc-forward-portlet/tree/master/src/main/java/arm/requestforward</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload