Title: Message
HI,
 
why do you have to write
JspCalendar clock = (JspCalendar)   pageContext.getAttribute("clock", PageContext.PAGE_SCOPE);
in your tag handler to access the bean.
cant i just write
JspCalendar clock =new JspCalendar()
 
Also, the bean may not be used in the JSP Page.. so pageContext.getAttribute will not work
 
The next statement
clock = (JspCalendar) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "dates.JspCalendar");
Again,
cant i just write
JspCalendar clock =new JspCalendar()
 
Please Help
 
Regards
Purav

 
 
-----Original Message-----
From: Yuri Grument [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 25, 2001 1:26 PM
Subject: Re: Accessing Beans from TagLibs

Hi, Puray
 
Tomcat includes all classes located in web-inf/classes and all jars located in web-inf/lib into CLASSPATH available to your tag handler.
So, you ccan just add
 
import somepackage.SomeBean;
 
into your tag handler.
 
For examle, in JSP you declare bean as
 
<jsp:useBean id='clock' scope='page' class='dates.JspCalendar' type="dates.JspCalendar" />
 
In tag handler the code will be next:
 
import dates.JspCalendar;
 
 
 
JspCalendar clock = (JspCalendar)   pageContext.getAttribute("clock", PageContext.PAGE_SCOPE);
 if ( clock == null ) {
  try {
      clock = (JspCalendar) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "dates.JspCalendar");
  } catch (ClassNotFoundException exc) {
          throw new InstantiationException(exc.getMessage());
  } catch (Exception exc) {
           throw new ServletException (" Cannot create bean of class "+"dates.JspCalendar", exc);
  }
  pageContext.setAttribute("clock", clock, PageContext.PAGE_SCOPE);
}
 Regards,
  Yuri
----- Original Message -----
From: Purav
Sent: Tuesday, December 25, 2001 9:12 AM
Subject: Accessing Beans from TagLibs

Hello,

 

I am using Tomcat 4.

I want to instantiate my Beans in my taglibs.

The Beans are located in web-inf/classes directory and taglibs are located in web-inf/lib directory

In JSP page I can use the jsp:useBean tag, but in my Taglib , how do I instantiate the bean. They are in a different directory�

Please Help

 

 

Purav

 

Reply via email to