Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-72072

RenderURL's Friendly URL prevents usage of the MVCRenderCommand

    Details

      Description

      The original discussion of the issue can be seen here.

      By default, <portlet:renderURL> returns the friendly URL string, when able to successfully convert. When using a link that is converted to a Friendly URL, the behavior changes from originally using a MVCRenderCommand.render to using the MVCPortlet.doView (or my override of it as seen below).

      Based on the intention behind Friendly URL, this should not be the behavior and should actually hit the RenderCommand class.

      Here is an example scenario to depict the issue:

      MyExamplePortlet.java
      // package/imports
      @Component(
      	immediate = true,
      	property = {
      		"com.liferay.portlet.display-category=category.sample",
      		"com.liferay.portlet.instanceable=true",
      		"javax.portlet.display-name=Test Portlet",
      		"javax.portlet.init-param.template-path=/",
      		"javax.portlet.init-param.view-template=/view.jsp",
      		"javax.portlet.resource-bundle=content.Language",
      		"javax.portlet.security-role-ref=power-user,user"
      	},
      	service = Portlet.class
      )
      public class MyExamplePortlet extends MVCPortlet {
      	
      	@Override
      	public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
      			throws IOException, PortletException {
      		_log.error("<><><><><><><> DoView Called <><><><><><><>");
      		super.doView(renderRequest, renderResponse);
      	}
      	
      	private static final Log _log = LogFactoryUtil.getLog(MyExamplePortlet.class);
      }
      
      MyExmapleRenderCommand.java
      // package/imports
      @Component(
      		immediate = true,
      		property = {
      				"javax.portlet.name=com_liferay_my_example_portlet_MyExamplePortlet",
      				"mvc.command.name=/exampleportlet/view"
      		},
      		service = MVCRenderCommand.class
      		)
      public class MyExampleRenderCommand implements MVCRenderCommand {
      
      	@Override
      	public String render(RenderRequest renderRequest, RenderResponse renderResponse) throws PortletException {
      		_log.error("<|><|><|><|> MyExampleRenderCommand.render Called <|><|><|><|>");
      		return "/view.jsp";
      	}
      
      	private static final Log _log = LogFactoryUtil.getLog(MyExampleRenderCommand.class);
      }
      
      view.jsp
      <%@ include file="/init.jsp" %>
      
      <p>
      	<%-- <b><liferay-ui:message key="exmaple-stuff.caption"/></b> --%>
      	<portlet:renderURL var="myRenderURL">
      		<portlet:param name="mvcRenderCommandName" value="/exampleportlet/view" />
      	</portlet:renderURL>
      	<p>The render URL for the portlet: <a href="${myRenderURL}">${myRenderURL}</a></p>
      </p>
      
      routes.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE routes PUBLIC "-//Liferay//DTD Friendly URL Routes 7.0.0//EN" 
       "http://www.liferay.com/dtd/liferay-friendly-url-routes_7_0_0.dtd">
      <routes>
      	<!-- Correct verison -->
      	<!-- 
      	<route>
      		<pattern>/render-it/</pattern>
      		<implicit-parameter name="mvcRenderCommandName">/exampleportlet/view</implicit-parameter>
      		<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
      		<implicit-parameter name="p_p_state">normal</implicit-parameter>
      		<implicit-parameter name="p_p_mode">view</implicit-parameter>
      	</route>
      	 -->
      	<!-- Intentational incorrect verison (to disable usage of Friendly URL) -->
      	
      	<route>
      		<pattern>/render-it/</pattern>
      		<implicit-parameter name="mvcRenderCommandName">/exampleportlet/view</implicit-parameter>
      		<implicit-parameter name="p_p_lifecycle">0</implicit-parameter>
      		<implicit-parameter name="p_p_state">normal</implicit-parameter>
      		<implicit-parameter name="p_p_mode">view-bad</implicit-parameter>
      	</route>
      	
      </routes>
      

      Steps to reproduce:

      1. Go to routes.xml and validate it matched the above (the correct version should be commented out).
      2. Build and deploy the module.
      3. Create new page, 1 column, with no portlets for simplicity.
      4. Add the portlet to the page, refresh page.
      5. Click link inside of portlet (an href to the generated renderURL)
        • Checking the log here should validate that the MVCRenderCommand was called last for the unfriendly URL.
      6. Comment out the invalid section and uncomment the valid section in routes.xml
      7. Redeploy, refresh the page with the deployed portlet. The friendly version should be visible.
      8. Click the link, and view logs.

      Expected:

      ... 
      ... <|><|><|><|> MyExampleRenderCommand.render Called <|><|><|><|>
      

      Actual:

      ... 
      ... <><><><><><><> DoView Called <><><><><><><>
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                shanon.mathai Shanon Mathai
                Reporter:
                shanon.mathai Shanon Mathai
                Participants of an Issue:
                Recent user:
                Esther Sanz
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  2 years, 17 weeks, 3 days ago

                  Packages

                  Version Package