Thursday, March 27, 2008

simple custom tag to make font red- Just notice steps and basics

 

1)       Create a TLD and put in web-inf

<taglib>

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

<uri>redtag</uri>

            <tag>

                        <name>redfont</name>

                        <tag-class>com.honeywell.sspglobal.report.dao.RedFont</tag-class>

                        <body-content>JSP</body-content>

            </tag>

</taglib>

 

2)       Create a JSP

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>

<%@ taglib prefix="ganesh" uri="redtag" %>

 

<html:html>

<HEAD>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

            pageEncoding="ISO-8859-1"%>

<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<META name="GENERATOR" content="IBM Software Development Platform">

<META http-equiv="Content-Style-Type" content="text/css">

<LINK href="../theme/Master.css" rel="stylesheet"

            type="text/css">

<TITLE></TITLE>

</HEAD>

 

<BODY>

<ganesh:redfont> This is to Test Ganesh</ganesh:redfont><br>

 

</BODY>

</html:html>

 

3)       Create a Tag handler class

 

 

package com.honeywell.sspglobal.report.dao;

import java.io.IOException;

 

import javax.servlet.jsp.JspException;

import javax.servlet.jsp.JspWriter;

import javax.servlet.jsp.tagext.TagSupport;

 

public class RedFont extends TagSupport

{

      JspWriter out;

      public int doStartTag() throws JspException

      {

                  out =pageContext.getOut();

                  System.out.println("In doStart Tag");

                  try

                  {

                  out.println("<font color=\"red\">");

                  }catch(IOException ie)

                  {

                              ie.getMessage();

                  }

                  return EVAL_BODY_INCLUDE;  

      }

     

      public int doEndTag() throws JspException

      {

                  try

                  {

                  out.println("<//font>");

                  }catch(IOException ie)

                  {

                              ie.getMessage();

                  }

                  return EVAL_PAGE;     

     

      }

     

}

No comments:

Post a Comment