0 Replies Latest reply on Apr 11, 2006 1:04 AM by bava syed

    Problem with JSP Output while using Custom TagLibs

    bava syed Newbie

      Hi
      I need an urgen help.. Please try helping me.. ! Thanks in advance..

      Environment Running under:

      JBoss Version : 4.0.2
      JDK Version : 1.4.2


      I am using the Custom Tag Lib to iterate over the data. I am having a problem with the output of the jsp while using the custom tag lib.

      The output from Jsp Page when accessed first time is :

      Hello
      Hello Again
      Hello Again
      Hello Again


      When I try to re-visit the page or refresh the page again then the output from the Jsp Page is :

      Hello
      Hello Again


      The source code:

      RepeatHelloTag.java:



      package com.masslight.tagExampleClasses;
      
      import javax.servlet.jsp.*;
      import javax.servlet.jsp.tagext.*;
      import java.io.*;
      
      public class RepeatHelloTag extends javax.servlet.jsp.tagext.BodyTagSupport {
       int count = 1;
       int numberOfIterations = 3;
       String greeting = new String("Hello <BR>");
       public int doStartTag() throws JspTagException {
       try {
       pageContext.getOut().print(greeting);
       } catch (Exception ex) {
       throw new JspTagException("IO problems");
       }
       return EVAL_BODY_BUFFERED;
       }
       public int doAfterBody() throws JspTagException {
       try {
       if (count < numberOfIterations) {
       count++;
       return EVAL_BODY_BUFFERED;
       }
       else {
       BodyContent bodyContent = getBodyContent();
       bodyContent.writeOut(getPreviousOut());
       return SKIP_BODY;
       }
       }
       catch (Exception e) {
       throw (new JspTagException("error"));
       }
       }
      }
      


      The Jsp File :


      tagExample.jsp

      <%@ page language="java" %>
      <%@ taglib uri="WEB-INF/tagExampleLib.tld" prefix="greeter" %>
      <html>
       <body>
       <greeter:RepeatHello>
       Hello Again<br>
       </greeter:RepeatHello>
       </body>
      </html>


      The TLD file :

      tagExampleLib.tld

      <?xml version="1.0" encoding="ISO-8859-1" ?>
      
      <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="htpp://www.w3.org/2001/XMLSchema-instance"
       version="2.0">
       <tlibversion>1.0</tlibversion>
       <jspversion>2.0</jspversion>
       <shortname>utility</shortname>
       <info>
       A simple tag library for the examples
       </info>
       <tag>
       <name>RepeatHello</name>
       <tagclass>com.masslight.tagExampleClasses.RepeatHelloTag</tagclass>
       <bodycontent>JSP</bodycontent>
       <info>Print Hello Multiple Times</info>
       </tag>
      </taglib>


      The Web.xml:

      <?xml version="1.0" encoding="ISO-8859-1"?>
      
      <!DOCTYPE web-app
       PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
       "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
      
      <web-app>
       <taglib>
       <taglib-uri>/WEB-INF/tagExampleLib.tld</taglib-uri>
       <taglib-location>/WEB-INF/tagExampleLib.tld</taglib-location>
       </taglib>
      </web-app>


      Regards
      Baba S