Featured post

Docker setup for Liferay 7 with MySQL

Thursday 3 November 2011

Create your own custom tld in Liferay at Portal Level.


If you are here that means you already know what is a TLD(Top Level Definition).
To include a TLD in Liferay at root level or you can say a portal level tld, you can follow the steps which will help you to create one on your own.

1. Create a hook name mytld.
2. Create mytld.jsp at /docroot/web-inf/jsps/html/taglib/ui/mytld/mytld.jsp.
3. Create an ext named mytld ext.
4. Move to web.xml by /docroot/web-inf/ext-web/docroot/web-inf/web.xml in ext.
5. Put below lines in web.xml.



<?xml version="1.0"?>

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<jsp-config>
<taglib>
<taglib-uri>http://liferay.com/tld/ui-ext</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-fc.tld</taglib-location>
</taglib>
</jsp-config>

</web-app>



6. Create a corresponding java class for ur taglib(if required) at /docroot/web-inf/ext-util-taglib/src/com/liferay/taglib/ui/MyTld.java in ext.
7. Write required code.
8. Move to /docroot/web-inf/ext-web/docroot/web-inf/tld/liferay-fc.tld.
9. Put below lines in liferay-fc.tld.


<?xml version="1.0" encoding="UTF-8"?>

<taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.1</jsp-version>
    <short-name>my-tld</short-name>
    <uri>http://liferay.com/tld/my-tld</uri>
    <tag>
            <name>foodcourt-discussion</name>
            <tag-class>com.liferay.taglib.ui.FoodCourtDiscussionTag</tag-class>
            <body-content>JSP</body-content>
            <attribute>
                <name>attribute-name1</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
            </attribute>
            <attribute>
                <name>attribute-name2</name>
                <required>true</required>
                <rtexprvalue>true</rtexprvalue>
            </attribute>
    </tag>
</taglib>


10. Deploy your ext.
11.Deploy your hook.
12.Restart your server.
12.Your new tld is ready to use.


Please let me know, if there is any concern about this Blog.

10 comments:

  1. thanks for sharing such nice information regarding above topic, Really its very useful for everything. Keep writing some more interesting topics as above.liferay training | liferay development

    ReplyDelete
  2. Hi, I am new to Liferay and I tried the above steps to create a new tld for my project. I try to use the newly created tld in a new portlet, but when defining the taglib I get the following error: The absolute uri: http://liferay.com/tld/my-tld cannot be resolved in either web.xml or the jar files deployed with this application. Can you please help me fix this error? Thank you

    ReplyDelete
  3. Have you define tld in your web.xml or jsp file?
    e.g. in jsp you can do this by
    <%@ taglib uri="http://liferay.com/tld/my-tld" prefix="my" %>
    or in web.xml as per taglib description!

    ReplyDelete
  4. Thank you for your reply, I figured out eventually. I had to import the tld file in my portlet.

    ReplyDelete
  5. Hi
    Please tell me attribute-name1 refer to what in java class , can u please list a java sample class?
    Thank you

    ReplyDelete
  6. Hi,

    attribute-name1 will refer to java bean name.
    Please let me know your email id so i can send you the java class example.

    ReplyDelete
  7. When I include my custom tld in liferay-plugin-package.properties I get the following error:
    ERROR [com.liferay.portal.kernel.deploy.auto.AutoDeployScanner][BaseDeployer:345] Unable to copy portal TLD myTld.tld

    Any suggestions?

    ReplyDelete
  8. Could you please provide the sample java for the same ?

    ReplyDelete
  9. wonderful information, I had come to know about your blog from my friend nandu , hyderabad,i have read atleast 7 posts of yours by now, and let me tell you, your website gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanks a ton once again, liferay training in hyderabad

    ReplyDelete
  10. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete