Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2004

Tip: Looking for answers? Try searching our database.

Nested Tags : Jakarta Taglibs

Thread view: 
Boni Gopalan - 29 Apr 2004 21:55 GMT
Hi All,

I am very confused with Jakarta Documentation.  It says that if I
return EVAL_BODY_AGAIN, or some other constant like that from
doAfterBody(), The Tag Body will be 'evaluated' again.  What I am
expecting is, If By Tag Body Has some more custom tags, those will be
Processed by the System, and finally I will get my beautiful HTML
output.  How ever it is not happening.  My Inner Tags are ignored by
the system, and I get no HTML output.  Evaluation of the custom Tag
happens only for one level.

Is this the expected behaviour ?, Or I am doing some blunder ?.  I
feel it is a blunder from my side.

Please let me know.

Thanks
Boni

My Tag Lib File (. tld) looks like this,

##############################################################################
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag
Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
   <tlibversion>1.0</tlibversion>
   <jspversion>1.1</jspversion>
   <shortname>customlibrary</shortname>
   <description>My controls taglibrary.</description>
   <uri>/mytaglib</uri>
   <tag>
       <name>PERSON</name>
       <tag-class>com.controltest.PersonControl</tag-class>
       <description></description>
       <bodycontent>JSP</bodycontent>
       <attribute>
           <name>name</name>
           <required>false</required>
       </attribute>
       <attribute>
           <name>age</name>
           <required>true</required>
       </attribute>
       <attribute>
           <name>phone</name>
           <required>true</required>
       </attribute>        
   </tag>
   <tag>
       <name>PERSONAL_INFO</name>
       <tag-class>com.controltest.PersonalInfo</tag-class>
       <description></description>
       <bodycontent>JSP</bodycontent>
       <attribute>
           <name>name</name>
           <required>false</required>
       </attribute>
       <attribute>
           <name>age</name>
           <required>true</required>
       </attribute>
   </tag>    
   <tag>
       <name>CONTACT_INFO</name>
       <tag-class>com.controltest.ContactInfo</tag-class>
       <description></description>
       <bodycontent>JSP</bodycontent>
       <attribute>
           <name>phone</name>
           <required>false</required>
       </attribute>
   </tag>        
</taglib>
##############################################################################

My JSP File is like this,

##############################################################################

<!--Generated by WebLogic Workshop-->
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%>
<%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
<%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%>
<%@ taglib uri="mytag.tld" prefix="mytag"%>
<netui:html>
 <head>
   <title>Web Application Page</title>
 </head>
 <body>
   <p>
     <mytag:PERSON name="Neeraj" age="64" phone="732-227-5753"/>
   </p>
 </body>
</netui:html>

##############################################################################

My PersonControl.java Looks like,

##############################################################################

package com.controltest;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class PersonControl  extends BodyTagSupport
{
   private String name = "";
   private String age = "";
   private String phone = "";
   private BodyContent bodyContent = null;   
   private int check = 0;
   
    public void setName(String name)
    {
        this.name = name;
    }
    public void setAge(String age)
    {
        this.age = age;
    }
    public void setPhone(String phone)
    {
        this.phone = phone;
    }    
   
    public int doStartTag() throws JspException//, java.io.IOException,
Exception
    {
       JspWriter out = pageContext.getOut();
       try
       {        
       //out.println(" <custom:CONTACT_INFO name = " + name + " age =
" + age +"/>");
       out.println("<%@ page language='java'
cont'entType='text/html;charset=UTF-8'%>");
       out.println("<%@ taglib uri='netui-tags-databinding.tld'
prefix='netui-data'%>");
       out.println("<%@ taglib uri='netui-tags-html.tld'
prefix='netui'%>");
       out.println("<%@ taglib uri='netui-tags-template.tld'
prefix='netui-template'%>");
       out.println("<%@ taglib uri='mytag.tld' prefix='mytag'%>");
       out.println("<netui:html>");
       out.println("<mytag:PERSONAL_INFO name='Neeraj' age='64'/>");
       }
       catch (Exception e){}
       if (check == 0)
           check = 1;
       else
           check = 0;
       return EVAL_BODY_TAG;
    }
   
    public int doEndTag() throws JspException
    {
       JspWriter out = pageContext.getOut();
       try
       {
           //out.println("</TD></TR</TABLE>");
           //pageContext.getOut().write("<table border='1'><tr><td><h3>" +
name + "</h3></td></tr><tr><td>");
           //out.println("</custom:CONTACT_INFO>");
           //bodyContent.flush();
       }
       catch (Exception e)
       {
           throw new JspTagException(e.getMessage());
       }       
       if (count < 2) return EVAL_BODY_AGAIN;
       return SKIP_BODY;
    }
   private BodyContent body = getBodyContent();      
   public void doInitBody()
   {
       body = getBodyContent();
   }
   public void setBodyContent (BodyContent b)
   {
       body = b;
   }
   int count = 0;
   public int doAfterBody()
   {
       count++;
       if (count < 2) return EVAL_BODY_AGAIN;
       return SKIP_BODY;
   }
   
}
##############################################################################
Christophe Vanfleteren - 29 Apr 2004 22:10 GMT
> Hi All,
>
[quoted text clipped - 9 lines]
> Is this the expected behaviour ?, Or I am doing some blunder ?.  I
> feel it is a blunder from my side.

Yes, tags don't work that way. As far as the server is concerned, anything
the tags outputs is ordinary HTML, and will not get reinterpreted.

> Please let me know.
>
> Thanks
> Boni

<snip code>

Signature

Kind regards,
Christophe Vanfleteren



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.