<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Define a "default render" command for a MVCPortlet?</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=102946669" />
  <subtitle>Define a "default render" command for a MVCPortlet?</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=102946669</id>
  <updated>2026-05-09T05:08:58Z</updated>
  <dc:date>2026-05-09T05:08:58Z</dc:date>
  <entry>
    <title>RE: Define a "default render" command for a MVCPortlet?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111898705" />
    <author>
      <name>Victor Soares</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111898705</id>
    <updated>2018-12-29T13:04:04Z</updated>
    <published>2018-12-29T13:04:04Z</published>
    <summary type="html">&lt;p&gt;Just as a note: using &amp;quot;mvc.command.name=/&amp;quot; will work to
  render a MVC command, however, there are two issues with this method:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;The first one is that is an inconsistent behavior in the portal side,
  one cannot put any command there, just the one called &amp;quot;/&amp;quot;.&lt;br /&gt;
  &lt;br /&gt; The second one is that will break other portlet modes, like edit.&lt;/p&gt;</summary>
    <dc:creator>Victor Soares</dc:creator>
    <dc:date>2018-12-29T13:04:04Z</dc:date>
  </entry>
  <entry>
    <title>RE: Define a "default render" command for a MVCPortlet?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111560724" />
    <author>
      <name>Adrian Rodriguez Monedero</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111560724</id>
    <updated>2018-11-15T12:53:37Z</updated>
    <published>2018-11-15T12:53:37Z</published>
    <summary type="html">&lt;p&gt;After checking the source code of MVCPortlet in Liferay 7.0, it seems
  as you could define a default render command declaring this component
  property of your display command:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&amp;quot;mvc.command.name=/&amp;quot;&lt;/p&gt;</summary>
    <dc:creator>Adrian Rodriguez Monedero</dc:creator>
    <dc:date>2018-11-15T12:53:37Z</dc:date>
  </entry>
  <entry>
    <title>RE: Define a "default render" command for a MVCPortlet?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=103081048" />
    <author>
      <name>Minhchau Dang</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=103081048</id>
    <updated>2018-01-23T16:25:49Z</updated>
    <published>2018-01-23T16:25:49Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;Thomas Kellerer:&lt;/div&gt;&lt;blockquote&gt;There is no method getRenderMVCCommandCache() in MVCPortlet and access to the instance variable _mvcRenderCommandCache is private. So I don&amp;#39;t see how I could use that cache.&lt;/blockquote&gt;&lt;br /&gt;Whether that method is available depends on the version of com.liferay.portal.kernel you are compiling against, and to some extent which version of Liferay you are running.&lt;br /&gt;&lt;br /&gt;Based on the blame on the file, the method wasn&amp;#39;t added until &lt;a href="https://issues.liferay.com/browse/LPS-68922"&gt;LPS-68922&lt;/a&gt;, which has a DE-8 label. It also has a fix version of 7.0.3 GA4, so if you&amp;#39;re running 7.0.2 GA3 or earlier or you built from source before DE-8, the method really isn&amp;#39;t available.&lt;br /&gt;&lt;br /&gt;If you&amp;#39;re using one of the later releases, checking the releases between DE-7 (2.12.x) and DE-8 (2.16.x), the earliest version of com.liferay.portal.kernel that provides that method is 2.13.0, so if your dependency version is anything lower than that (it&amp;#39;s typical to have a dependency version that is 2.0.0 or 2.6.0 if you follow Liferay examples), the compiler would be unable to find it.</summary>
    <dc:creator>Minhchau Dang</dc:creator>
    <dc:date>2018-01-23T16:25:49Z</dc:date>
  </entry>
  <entry>
    <title>RE: Define a "default render" command for a MVCPortlet?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=103069757" />
    <author>
      <name>Thomas Kellerer</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=103069757</id>
    <updated>2018-01-23T11:16:58Z</updated>
    <published>2018-01-23T11:16:58Z</published>
    <summary type="html">Thanks for the answer. &lt;br /&gt;&lt;br /&gt;There is no method getRenderMVCCommandCache() in MVCPortlet and access to the instance variable _mvcRenderCommandCache is private. &lt;br /&gt;So I don&amp;#39;t see how I could use that cache. &lt;br /&gt;&lt;br /&gt;But, using the @Reference annotation seems to work.</summary>
    <dc:creator>Thomas Kellerer</dc:creator>
    <dc:date>2018-01-23T11:16:58Z</dc:date>
  </entry>
  <entry>
    <title>RE: Define a "default render" command for a MVCPortlet?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=103042538" />
    <author>
      <name>Minhchau Dang</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=103042538</id>
    <updated>2018-01-22T18:12:32Z</updated>
    <published>2018-01-22T18:12:32Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;div class="quote-title"&gt;Thomas Kellerer:&lt;/div&gt;&lt;blockquote&gt;Creating an additional instance of the render command feels like a hack though.&lt;/blockquote&gt;&lt;br&gt;It probably also won't work if your DisplayCommand needed to have any of its references satisfied by OSGi, since you're essentially instantiating the object yourself instead of letting OSGi do it for you.&lt;br&gt;&lt;br&gt;An alternate option is to use the MVCCommandCache to grab the existing object during the render phase, if it hasn't already been set. That allows you to take advantage of Liferay storing the references.&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Override
public void render(RenderRequest renderRequest, RenderResponse renderResponse)
    throws IOException, PortletException {

    if (displayData == null) {
        displayData = getRenderMVCCommandCache().getMVCCommand("def");
    }

    // ...
}&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;Another option is to use @Reference to get the existing component instantiated/managed by OSGi. This allows you to take advantage of OSGi storing the references.&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Reference(target="(&amp;amp;amp;(javax.portlet.name=abc)(mvc.command.name=def))")
private MVCRenderCommand displayData;&lt;/code&gt;&lt;/pre&gt;&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Minhchau Dang</dc:creator>
    <dc:date>2018-01-22T18:12:32Z</dc:date>
  </entry>
  <entry>
    <title>RE: Define a "default render" command for a MVCPortlet?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=103030006" />
    <author>
      <name>Thomas Kellerer</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=103030006</id>
    <updated>2018-01-22T14:08:48Z</updated>
    <published>2018-01-22T14:08:48Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;My workaround for now is the following hack in the render() method of the portlet:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;public class MyDisplayPortlet
    extends MVCPortlet {

    private final DisplayCommand displayData = new DisplayCommand();
    
    @Override
    public void render(RenderRequest renderRequest, RenderResponse renderResponse)
        throws IOException, PortletException {

        String renderCmd = ParamUtil.getString(renderRequest, "mvcRenderCommandName", null);
        
        if (renderCmd == null) {
            String mvcPath = displayData.render(renderRequest, renderResponse);
            renderRequest.setAttribute(getMVCPathAttributeName(renderResponse.getNamespace()), mvcPath);
        }
        
        super.render(renderRequest, renderResponse); 
    }
}&lt;/code&gt;&lt;/pre&gt;Creating an additional instance of the render command feels like a hack though.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Thomas Kellerer</dc:creator>
    <dc:date>2018-01-22T14:08:48Z</dc:date>
  </entry>
  <entry>
    <title>Define a "default render" command for a MVCPortlet?</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=102946668" />
    <author>
      <name>Thomas Kellerer</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=102946668</id>
    <updated>2018-01-19T08:56:12Z</updated>
    <published>2018-01-19T08:56:12Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;All examples for MVCPortlets show the portlet definition with a default view jsp.&lt;br&gt;&lt;br&gt;However as I need to retrieve data to populate that view, I would like to do that in a (reusable) render command. &lt;br&gt;&lt;br&gt;But I can't find a way to define a the render command in the portlet annotation instead of the view jsp:&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Component(
    immediate = true,
    property = {
        "com.liferay.portlet.display-category=MyPortlets",
        "com.liferay.portlet.instanceable=false",
        "javax.portlet.display-name=Display Portlet",
        "javax.portlet.init-param.view-template=/myportlet/list_data.jsp",
        "javax.portlet.name=my_portlet",
        "com.liferay.portlet.ajaxable=false",
    },
    service = Portlet.class
)&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;But instead of referencing a .jsp page in &lt;span style="font-family: Courier New"&gt;javax.portlet.init-param.view-template&lt;/span&gt;, I would like to tell Liferay that it should call a specific RenderCommand when the portlet is initially displayed. &lt;br&gt;&lt;br&gt;I would like to avoid putting that into the Portlet's render() method,  because that would duplicate the code between the RenderCommand and the render() method.&lt;br&gt;&lt;br&gt;How can I do that?&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Thomas Kellerer</dc:creator>
    <dc:date>2018-01-19T08:56:12Z</dc:date>
  </entry>
</feed>
