Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: Liferay 7.1 and Custom JSP Taglibs
I am currently moving an application from Liferay 6.2 to Liferay 7.1. I'm using OSGI JAR modules instead of a WAR for my web application. The issue is that in my old implementation all I had to do was put a tags directory in WEB-INF and name the files *.tag. And referencing the tags in the portlet jsps was as simple as including the taglib
<%@ taglib tagdir="/WEB-INF/tags/" prefix="tt"%>
And then I could build the *.tag files as JSPs and call them like
<tt:myNewTag name="My New Tag"/>
But with OSGI modules I'm not sure how to do that. I've come across some tutorials that say you need two projects, one to hold the taglib definition XML and classes that extend IncludeTag, and one hook that contains your JSPs that are custom tag jsps. But 7.1 doesn't support hooks anymore, so I'm at a loss on how to set this up.
I have a web OSGI module that compiles and deploys to a jar, I need this jar to reference another jar with the custom tags. And the jar with the custom tags module needs to be available to all portlets in the portal after deployed. How would I do this?
<%@ taglib tagdir="/WEB-INF/tags/" prefix="tt"%>
And then I could build the *.tag files as JSPs and call them like
<tt:myNewTag name="My New Tag"/>
But with OSGI modules I'm not sure how to do that. I've come across some tutorials that say you need two projects, one to hold the taglib definition XML and classes that extend IncludeTag, and one hook that contains your JSPs that are custom tag jsps. But 7.1 doesn't support hooks anymore, so I'm at a loss on how to set this up.
I have a web OSGI module that compiles and deploys to a jar, I need this jar to reference another jar with the custom tags. And the jar with the custom tags module needs to be available to all portlets in the portal after deployed. How would I do this?
The easiest way to see an OSGi-based taglib for Liferay is probably to go to the source.
The flags tag library is pretty darn simple (I think it only has one tag, actually), but it has the necessary stuff to create a custom tag library you can use in your jsps.
https://github.com/liferay/liferay-portal/tree/7.1.x/modules/apps/flags/flags-taglib
The flags tag library is pretty darn simple (I think it only has one tag, actually), but it has the necessary stuff to create a custom tag library you can use in your jsps.
https://github.com/liferay/liferay-portal/tree/7.1.x/modules/apps/flags/flags-taglib
Great information, thanks!
I've looked into a few of these, I guess the issue is correctly using this taglib within my jsp portlets, because those are modules as well. Say I wanted to take this example, tweak it and then deploy it to see my changes. If I can do that I'll be able to use this example to my advantage.
Are there any examples on a module that uses this taglib?? What needs to be done to make that happen?
I've looked into a few of these, I guess the issue is correctly using this taglib within my jsp portlets, because those are modules as well. Say I wanted to take this example, tweak it and then deploy it to see my changes. If I can do that I'll be able to use this example to my advantage.
Are there any examples on a module that uses this taglib?? What needs to be done to make that happen?
Message boards does:
https://github.com/liferay/liferay-portal/blob/7.1.x/modules/apps/message-boards/message-boards-web/build.gradle#L11
https://github.com/liferay/liferay-portal/blob/7.1.x/modules/apps/message-boards/message-boards-web/src/main/resources/META-INF/resources/message_boards/init.jsp#L26
https://github.com/liferay/liferay-portal/blob/7.1.x/modules/apps/message-boards/message-boards-web/src/main/resources/META-INF/resources/message_boards/view_thread_message.jsp#L163-L170
https://github.com/liferay/liferay-portal/blob/7.1.x/modules/apps/message-boards/message-boards-web/build.gradle#L11
https://github.com/liferay/liferay-portal/blob/7.1.x/modules/apps/message-boards/message-boards-web/src/main/resources/META-INF/resources/message_boards/init.jsp#L26
https://github.com/liferay/liferay-portal/blob/7.1.x/modules/apps/message-boards/message-boards-web/src/main/resources/META-INF/resources/message_boards/view_thread_message.jsp#L163-L170
Looking through the code in flags-taglib and I noticed something in the file com.liferay.flags.taglib.servlet.taglib.FlagsTag.java, there is an override for getPage() that returns
/flags/page.jsp
Where is this JSP defined? Is this something in the portal source that we would be overriding? I can't find this file anywhere, so I'm guessing it's a liferay portal template of some sort that is simply overridden
/flags/page.jsp
Where is this JSP defined? Is this something in the portal source that we would be overriding? I can't find this file anywhere, so I'm guessing it's a liferay portal template of some sort that is simply overridden
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™