tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Holmes III, William S" <william.s.holmes....@lmco.com>
Subject RE: useBean tag
Date Fri, 04 Aug 2000 13:38:29 GMT
I thought making beans include servlet information (#include
javax.servlet.*) was frowned upon.

> -----Original Message-----
> From:	Steven.Shaw@savillemail.com [SMTP:Steven.Shaw@savillemail.com]
> Sent:	Thursday, August 03, 2000 10:28 PM
> To:	tomcat-user@jakarta.apache.org
> Subject:	useBean tag
> 
> 
> 
> The useBean tag seems to be less than useful when accessing session
> attributes.
> Say I have a bean called "com.foo.beans.CustomerBean" i.e. that is it's
> attribute-name set from a servlet. I then try to access the bean from a
> JSP
> using the useBean tag.
> 
>      <jsp:useBean id="customerBean" .... />
> 
> How can I do this? It seems I need something like:
> 
>      <jsp:useBean id="customerBean" scope="session"
> name="com.foo.beans.CustomerBean" />
> 
> Currently I am working around this with some code like this:
> 
>      <% customerBean = CustomerBean.get(request); %>
> 
> The CustomerBean.get is a static method which lazily instantiates the
> bean:
> 
> public class CustomerBean {
>     private static BEAN_NAME = "com.foo.beans.CustomerBean";
> 
>     public static CustomerBean get(HttpRequest request) {
>         HttpSession session = request.getSession();
>         CustomerBean bean = (CustomerBean)
> session.getAttribute(BEAN_NAME);;
>         if (bean == null) {
>             synchronized (session) {
>                 bean = (CustomerBean) session.getAttribute(BEAN_NAME);;
>                 if (bean == null) {
>                     bean = new CustomerBean();
>                     session.setAttribute(BEAN_NAME, bean);
>                 }
>             }
>         }
>         return careSession;
>     }
> .....
> 
> Any comments. Am I missing something?
> 
> cheers,
> 
> Steve.
> 

Mime
View raw message