Quantcast
Channel: Adobe Community : Popular Discussions - CQ5 (read only)
Viewing all articles
Browse latest Browse all 12476

creating custom tag library- AEM, CQ 5.6

$
0
0

Hi ,

 

I am creating a custom tag library and want to use it in one of the components I have created. I have made a bundle inside src/com.mycompany.test.TestBundle/com.mycompany.test.TestBundle.bnd and created my java tag class inside com.mycompany.test.TestBundle/src/main/java/com/mycompany/test/DateTagClass.java and the tld in com.mycompany.test.TestBundle/src/main/resources/META_INF/dateTaglib.tld. Here is the code for both the java tag class and the tld

 

----------------

tag class

 

 

package com.mycompany.test;

 

import java.io.IOException;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

import javax.servlet.jsp.JspException;

import javax.servlet.jsp.JspWriter;

import javax.servlet.jsp.tagext.SimpleTagSupport;

/**

*

* @author ankit-chandrawat

*/

public class DateTagClass extends SimpleTagSupport {

   

    public void doTag() throws JspException, IOException {

    JspWriter out = getJspContext().getOut();

    out.println(getTodayDate());

    }

   

   private String getTodayDate() {

        DateFormat df = new SimpleDateFormat("dd MMMM yyyy");

        String formattedDate = df.format(new Date());

        return formattedDate;

    }

}

 

--------------

tld file

 

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

<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd">

 

  <tlib-version>1.0</tlib-version>

  <jsp-version>2.0</jsp-version>

  <short-name>date</short-name>

    <uri>src/main/resources/META_INF/dateTaglib.tld</uri>

  <tag>

    <name>todaysDate</name>

    <tag-class>com.mycompany.test.DateTagClass</tag-class>

    <body-content>empty</body-content>

  </tag>

</taglib>

--------------------------------------------------

I am trying to use it inside a component jsp that I have created as :

 

<%@taglib prefix="date" uri="src/main/resources/META_INF/dateTaglib.tld"%>

 

But with the above taglib include in place, all I see is a blank page. I am trying this on author and have not pushed it to publisher yet. I believe it is not able to recognize the tld. Could you please help me on this.

 

Thanks

Ankit


Viewing all articles
Browse latest Browse all 12476

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>