Message Boards

Create own custom tag library in Liferay 7.0

thumbnail
Sandip Patel, modified 7 Years ago.

Create own custom tag library in Liferay 7.0

Regular Member Posts: 205 Join Date: 1/5/11 Recent Posts
Hi,
I am using Liferay EE GA1 7.0. I need to create a own custom tag library.
I have found that in Liferay previous version we can achieve this by hook and ext plugin bur I think In Liferay 7 exp plugin is not longer supported.

Please give you input how to create own custom tag library in Liferay 7.

Regards,
Sandip Pate
thumbnail
David H Nebinger, modified 7 Years ago.

RE: Create own custom tag library in Liferay 7.0

Liferay Legend Posts: 14917 Join Date: 9/2/06 Recent Posts
It's still just a jar with your tag stuff. Instead of promoting to the portal, just bundle it with each war that uses the tag lib.
thumbnail
Chema Balsas, modified 7 Years ago.

RE: Create own custom tag library in Liferay 7.0

Regular Member Posts: 127 Join Date: 2/25/13 Recent Posts
Hey Sandip,

You should be able to create and deploy simple modules with your taglibs. You can use some of the existing taglib modules as a guideline:



Hope it helps!
thumbnail
Sandip Patel, modified 7 Years ago.

RE: Create own custom tag library in Liferay 7.0

Regular Member Posts: 205 Join Date: 1/5/11 Recent Posts
I got my answer in below link.
http://stackoverflow.com/questions/38522892/creating-a-custom-taglib-in-liferay-7
https://github.com/liferay/liferay-portal/tree/master/modules/apps/foundation/map/map-taglib

Thanks,
thumbnail
David H Nebinger, modified 7 Years ago.

RE: Create own custom tag library in Liferay 7.0

Liferay Legend Posts: 14917 Join Date: 9/2/06 Recent Posts
That's exactly what Chema was pointing you to...






Come meet us at the LSNA!
zhou zhou, modified 6 Years ago.

RE: Create own custom tag library in Liferay 7.0

New Member Post: 1 Join Date: 2/10/17 Recent Posts
I solve this problem by https://github.com/liferay/liferay-portal/tree/master/modules/apps/foundation/map/map-taglib


and portlet page view.jsp
<%@ taglib uri="http://liferay.com/tld/map" prefix="liferay-map" %>
<liferay-map:map-display />

thanks
Thomas Kellerer, modified 6 Years ago.

RE: Create own custom tag library in Liferay 7.0

Expert Posts: 490 Join Date: 6/9/08 Recent Posts
I managed to get my taglib working in my JSP pages, however each time I display such a page I see the following exception in the Liferay logfile:

12:26:45,078 ERROR [http-nio-8080-exec-12][FreeMarkerManager:208] Unable to add taglib my_tags to context
FreeMarker template error:
freemarker.template.TemplateModelException: Error while loading tag library for URI "/META-INF/my_tags.tld" from TLD location "servletContext:/META-INF/my_tags.tld"; see cause exception.
        at freemarker.ext.jsp.TaglibFactory.get(TaglibFactory.java:260)
        at com.liferay.portal.template.freemarker.internal.FreeMarkerManager$TaglibFactoryWrapper.get(FreeMarkerManager.java:647)
        at com.liferay.portal.template.freemarker.internal.FreeMarkerManager.addTaglibSupport(FreeMarkerManager.java:205)
        at com.liferay.taglib.util.ThemeUtil.doIncludeFTL(ThemeUtil.java:276)
        at com.liferay.taglib.util.ThemeUtil.doDispatch(ThemeUtil.java:157)
        at com.liferay.taglib.util.ThemeUtil.includeFTL(ThemeUtil.java:100)
        at com.liferay.taglib.util.ThemeUtil.include(ThemeUtil.java:82)
        at com.liferay.taglib.theme.WrapPortletTag.doEndTag(WrapPortletTag.java:101)
        at org.apache.jsp.html.common.themes.portlet_jsp._jspService(portlet_jsp.java:1863)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


The error is thrown by the Freemarker engine, so it doesn't affect my JSP pages (they do work properly).

But it would still be nice to know how to get rid of that exception.
Thomas Kellerer, modified 6 Years ago.

RE: Create own custom tag library in Liferay 7.0

Expert Posts: 490 Join Date: 6/9/08 Recent Posts
Thomas Kellerer:
But it would still be nice to know how to get rid of that exception.

Actually it wouldn't just be "nice" - it is pretty important. Currently each and every page access (even pages not using my own JSP) will throw and log that exception.

This makes it nearly impossible to find real error messages in the logfile and it would put a high burden on the production server, if I can't fix this.
thumbnail
David H Nebinger, modified 6 Years ago.

RE: Create own custom tag library in Liferay 7.0

Liferay Legend Posts: 14917 Join Date: 9/2/06 Recent Posts
Looks like FM is having trouble accessing the tld file using "servletcontext:/META-INF/my_tags.tld". That is likely true because "servletcontext" is likely referring to some other context.

Is your TLD properly registered and mapped such that FM would be able to dynamically load it when it needs it?

Looking at the relevant code, you can see that FM is trying to fetch the TLD: https://github.com/apache/incubator-freemarker/blob/2.3-gae/src/main/java/freemarker/ext/jsp/TaglibFactory.java#L178






Come meet me at the 2017 LSNA!
Thomas Kellerer, modified 6 Years ago.

RE: Create own custom tag library in Liferay 7.0

Expert Posts: 490 Join Date: 6/9/08 Recent Posts
David H Nebinger:
Is your TLD properly registered and mapped such that FM would be able to dynamically load it when it needs it?

I assume that they are, as my portlets can use the tags. But I am not sure how I would "properly" do that. There is no documentation on how to "properly register" a TLD.

But anyhow: the error messages went away when I removed the file taglib-mappings.properties from my module.
Mithun Seal, modified 3 Years ago.

RE: Create own custom tag library in Liferay 7.0

New Member Posts: 4 Join Date: 10/16/19 Recent Posts
I think I am facing similar problem here.

As part of Liferay upgrade from 6.2 to 7.2, I am updating the code and using war file to deploy in Liferay 7.2. I am facing some issue to deploy custom taglib project in 7.2.

If I create a liferay-plugin-packages.properties and add below entry, I am able to deploy the war but in runtime I am getting freemarker template exception. With this I am unable to access the application. Any idea what I am doing wrong?

Provide-Capability=osgi.extender;osgi.extender=\"jsp.taglib\";uri=\"/WEB-INF/tld/my-custom.tld\"

Error:
[FreeMarkerManager:216] Unable to add taglib liferay_portlet to context
freemarker.template.TemplateModelException: Error while loading tag library for URI "/META-INF/liferay-portlet-ext.tld" from TLD location "servletContext:/META-INF/liferay-portlet-ext.tld"; see cause exception.

Caused by: freemarker.ext.jsp.TaglibFactory$TldParsingSAXException: In bundleresource://1113.fwk948623530:31/META-INF/liferay-portlet-ext.tld, at line 528, column 8:_Can't load class "com.liferay.taglib.portletext.RuntimeTag" for custom tag "runtime". [Sanitized]