<?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>Freemarker &amp; JSP Tags</title>
  <link rel="self" href="https://liferay.dev/fr/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=8889656" />
  <subtitle>Freemarker &amp; JSP Tags</subtitle>
  <id>https://liferay.dev/fr/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=8889656</id>
  <updated>2026-06-26T18:55:55Z</updated>
  <dc:date>2026-06-26T18:55:55Z</dc:date>
  <entry>
    <title>RE: Freemarker &amp; JSP Tags</title>
    <link rel="alternate" href="https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=28174891" />
    <author>
      <name>Mika Koivisto</name>
    </author>
    <id>https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=28174891</id>
    <updated>2013-09-10T20:03:21Z</updated>
    <published>2013-09-10T20:03:21Z</published>
    <summary type="html">Hari it&amp;#39;s not a real HttpServletRequest</summary>
    <dc:creator>Mika Koivisto</dc:creator>
    <dc:date>2013-09-10T20:03:21Z</dc:date>
  </entry>
  <entry>
    <title>RE: Freemarker &amp; JSP Tags</title>
    <link rel="alternate" href="https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=28154924" />
    <author>
      <name>Hari babu</name>
    </author>
    <id>https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=28154924</id>
    <updated>2013-09-10T09:55:10Z</updated>
    <published>2013-09-10T09:55:10Z</published>
    <summary type="html">Hi Mika&lt;br /&gt;&lt;br /&gt;You have the request available to the velocity template by un-check the &amp;#34;Cachebale&amp;#34; checkbox on CMS templates</summary>
    <dc:creator>Hari babu</dc:creator>
    <dc:date>2013-09-10T09:55:10Z</dc:date>
  </entry>
  <entry>
    <title>RE: Freemarker &amp; JSP Tags</title>
    <link rel="alternate" href="https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=9411228" />
    <author>
      <name>Erik Andersson</name>
    </author>
    <id>https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=9411228</id>
    <updated>2011-06-16T22:55:42Z</updated>
    <published>2011-06-16T22:55:42Z</published>
    <summary type="html">Thanks Mika. Too bad though, I would&amp;#39;ve loved to be able to do that.</summary>
    <dc:creator>Erik Andersson</dc:creator>
    <dc:date>2011-06-16T22:55:42Z</dc:date>
  </entry>
  <entry>
    <title>RE: Freemarker &amp; JSP Tags</title>
    <link rel="alternate" href="https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=9411222" />
    <author>
      <name>Mika Koivisto</name>
    </author>
    <id>https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=9411222</id>
    <updated>2011-06-16T22:53:16Z</updated>
    <published>2011-06-16T22:53:16Z</published>
    <summary type="html">Hey Erik,&lt;br /&gt;&lt;br /&gt;You can&amp;#39;t use taglibs in web content templates because they don&amp;#39;t have access to the real HttpServletRequest.</summary>
    <dc:creator>Mika Koivisto</dc:creator>
    <dc:date>2011-06-16T22:53:16Z</dc:date>
  </entry>
  <entry>
    <title>RE: Freemarker &amp; JSP Tags</title>
    <link rel="alternate" href="https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=9411199" />
    <author>
      <name>Erik Andersson</name>
    </author>
    <id>https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=9411199</id>
    <updated>2011-06-16T22:45:03Z</updated>
    <published>2011-06-16T22:45:03Z</published>
    <summary type="html">Hi Ray,&lt;br /&gt;&lt;br /&gt;Thanks for this. I&amp;#39;m trying to get the liferay taglibs to work in web content templates (ftl) by adding:&lt;br /&gt;&lt;span style="font-family: Courier New"&gt;&amp;lt;#assign aui = PortalJspTagLibs[&amp;#34;/WEB-INF/tld/liferay-aui.tld&amp;#34;] /&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This doesn&amp;#39;t seem to work, however, the console prints:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family: Courier New"&gt;Expression PortalJspTagLibs is undefined on line 1, column 16 in 2028911937.&lt;br /&gt;The problematic instruction:&lt;br /&gt;----------&lt;br /&gt;==&amp;gt; assignment: aui=PortalJspTagLibs[&amp;#34;/WEB-INF/tld/liferay-aui.tld&amp;#34;] [on line 1, column 1 in 2028911937]&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Are you able to use the taglibs in web content templates?&lt;br /&gt;&lt;br /&gt;Cheers,&lt;br /&gt;Erik</summary>
    <dc:creator>Erik Andersson</dc:creator>
    <dc:date>2011-06-16T22:45:03Z</dc:date>
  </entry>
  <entry>
    <title>Freemarker &amp; JSP Tags</title>
    <link rel="alternate" href="https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=8889655" />
    <author>
      <name>Ray Augé</name>
    </author>
    <id>https://liferay.dev/fr/c/message_boards/find_message?p_l_id=119785294&amp;messageId=8889655</id>
    <updated>2011-05-20T14:34:43Z</updated>
    <published>2011-05-20T14:34:43Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Hey All,&lt;br&gt;&lt;br&gt;At ECS Greg Amerson and I did a workshop to show how, using freemarker &amp;amp; it's JSP Tags support, to overload portal/plugin jsps from your theme.&lt;br&gt;&lt;br&gt;I can't say it was easy to achieve the understanding to do get everything working, but we finally did and I just wanted to highlight the caveats that caused some pain (and hopefully from here it'll make it easier for everyone else).&lt;br&gt;&lt;br&gt;So, without further ado, here they are:&lt;br&gt;&lt;br&gt;&lt;strong&gt;*Freemarker doesn't accept '-' (dash) in identifiers*&lt;/strong&gt; including taglib or tag names (more on this later).&lt;br&gt;&lt;br&gt;&lt;strong&gt;Initializing a taglib for use&lt;/strong&gt;&lt;br&gt;	If the taglib belongs to the portal:&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#assign portlet = [b]PortalJspTagLibs[/b]["/WEB-INF/tld/liferay-portlet.tld"] /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;	If the taglib belongs to the theme (bundled with the theme plugin)&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#assign taglib = [b]ThemeJspTaglibs[/b]["/WEB-INF/tld/taglib.tld"] /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;	If the taglib contains a '-' (dash) in it's name, I would suggest a convention like:&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#assign [b]liferay_ui[/b] = PortalJspTagLibs["/WEB-INF/tld/liferay-ui.tld"] /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;strong&gt;Using JSP Tags&lt;/strong&gt;&lt;br&gt;	The syntax is strange and foreign but I guess we have to live with it. There are two syntax but in the Liferay tradition I will only show and suggest the one that works for all cases. I repeat the fact that freemarker doesn't work with tags that contain dashes in their name. This means we have to use the "map" syntax to call them. It also means we have to use the "short" closing tag syntax as well (not officially, but I couldn't get it to work consistently using the long form):&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;@[b]liferay_ui["message"][/b] key="message" /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;	And the short closing tag syntax&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;@liferay_ui["panel-container"] cssClass="message-boards-panels"&amp;amp;gt;
		...
[b]&amp;lt;!--@--&amp;gt;[/b]&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;strong&gt;Handling tag attributes&lt;/strong&gt;&lt;br&gt;	You can only quote string literals&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;@liferay_ui["message"] [b]key="message"[/b] /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;	When assigning objects (and remember there are no primitive types in template languages usually) you don't quote them&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;@liferay_ui["message"] [b]key=myKeyVar[/b] /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;	What about complex assignments then? I suggest another convention, use parentheses around complex/object assignments.&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;@liferay_ui["search-container-column-text"]
	href=(rowURL)
	name="my-column"
	value=[b]("something" + 15 + "something else")[/b]
/&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;	Note that freemarker provides "builtins" for conversions so that for instance you can assign numbers to string attributes:&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;@liferay_ui["search-container-column-text"]
	href=rowURL
	name="posts"
	value=(categoryDisplay.getSubcategoriesMessagesCount(curCategory)[b]?string[/b])
/&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;strong&gt;Accessing Static classes' methods and/or fields&lt;/strong&gt;&lt;br&gt;	You have to jump through a hoop here and leverage a utility of freemarker to wrap the static class so that it exposes the methods and/or fields&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#assign ParamUtil = [b]staticUtil[/b]["com.liferay.portal.kernel.util.ParamUtil"] /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;	After that, usage is as simple as:&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#assign portletResource = ParamUtil.getString(request, "portletResource") /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;strong&gt;Initializing an instance of a class&lt;/strong&gt;&lt;br&gt;	Here you have to also leverage a freemarker util or wrapper&lt;br&gt;	&lt;pre&gt;&lt;code&gt;&amp;amp;lt;#assign rssURLParams = objectUtil("com.liferay.portal.kernel.util.StringBundler") /&amp;amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;	&lt;br&gt;Finally, I've attached a sample similar to what I used at ECS-2011 (with a few changes to match above recommendations).&lt;br&gt;&lt;br&gt;The big points here is that you can achieve per theme UI changes so that you can apply those to only portions of your site(s), doing things like using AUI tags in your themes. You could make the same APP have completely different UIs in different sites without touching the core. You can even have this apply technique to jsps in plugin portlets.&lt;br&gt;&lt;br&gt;&lt;strong&gt;Note:&lt;/strong&gt; In order to see this in action you first &lt;strong&gt;have to apply it to a page or site&lt;/strong&gt;, and then &lt;strong&gt;make a Message Board Category of type "Question"&lt;/strong&gt;. Once you navigate into this category you will see the message "this-is-the-overloaded-view" just under the Category name.&lt;br&gt;&lt;br&gt;Hope it helps!&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Ray Augé</dc:creator>
    <dc:date>2011-05-20T14:34:43Z</dc:date>
  </entry>
</feed>
