Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: Cooperating tags not coooperating


Message #1 by "Lester Peterkin" <lesterdale@h...> on Wed, 28 Nov 2001 16:29:13
I have written some java code for a set fo cooperating tags, I am able to 
compile the parent tag class, but when I try to compile the child tag class 
 the compiler has no knowledge of the parent tag, I have tried to compile 
the book example on cooperating tags and arrived at the same problem, so 
could anyone help me, the code for my tags are below, the are both stored 
in the same 
directory(c:\jakarta-tomcat-3.2.3\webapps\exper\WEB-INF\classes\dev\jsp\tag
s\dbase

The code for the java files are as follows:


dbConnection.java
--------------------

package dev.jsp.tags.dbase;

import java.sql.*;
import java.util.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class dbConnection extends BodyTagSupport
{
  private String odbcDriver; 
  private String dataSource;
  private Connection conn = null;
  private Vector objStore;
  
  public void setOdbcDriver(String driver)
  {
    odbcDriver = driver;
  }
  public String getOdbcDriver()
  {
    return odbcDriver;
  }	
  public String getDataSource()
  {
    return dataSource;
  }	
  public void addObjStore(Object obj)
  {
    objStore.add(obj);
  }	 	
  public void setDataSource(String source)
  {
    dataSource = source;
  }
  
  public void doInitBody() throws JspException
  {
    objStore = new Vector();
	try
	{
	  Class.forName(getOdbcDriver());
	  conn = DriverManager.getConnection(getDataSource());
	}
	catch(ClassNotFoundException cnfe)
	{
	  System.err.println("ClassNotFoundException thrown in 
doInitBody():");
	  System.err.println(cnfe);
	  
	  throw new JspException(cnfe);
	}	
	catch(SQLException sqle)
	{
	  System.err.println("SQLException thrown in doInitBody():");
	  System.err.println(sqle);
	
      throw new JspException(sqle);	
	}
  }
  
  public int doEndTag() throws JspException
  {
   // Get the tag body information
   int i = 0;
   BodyContent tagBody = getBodyContent();
   
   String templateText = tagBody.getString().trim(); 
   try
   {
     PreparedStatement Query = conn.prepareStatement(templateText);
     Iterator elements = objStore.iterator();
   
     while(elements.hasNext())    
      Query.setString(i++, (String)elements.next());
   
    ResultSet results = Query.executeQuery();   
    pageContext.setAttribute("RESULTS", results); 
    return EVAL_PAGE;
   }
   catch(SQLException sqle)
   {
     System.err.println("SQLException thrown in doInitBody():");
     System.err.println(sqle);
	
     throw new JspException(sqle);	
   }
 }  	 
 public void release()
 {
   odbcDriver = null;
   dataSource = null;
   conn = null;
   objStore = null;
  super.release();
 }
}	

sqlValue.java
----------------------

package dev.jsp.tags.dbase;

import java.sql.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import dev.jsp.tags.dbase.*;

public class sqlValue extends TagSupport
{
  private String param;  
  
  public void setParam(String value)
  {
    param = value;
  }	
  public String getParam()
  {
    return param;
  }
  
  public int doStartTag() throws JspException
  {
    
	dbConnection parenTag = (dbConnection) 
this.findAncestorWithClass(this, dbConnection.class);	
	parentTag.addObjStore(param);
	
	return SKIP_BODY;
  }
}

  Return to Index