• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

passing beans..

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All, I was hoping somebody can shine a light on the problem I'm having trouble with.

If I have a JSP page which uses a bean ("DBBean").

DBBean is a 'page scope' bean and is used to connect to a DBCP

Now I want to refer to a second bean in which is code to return certain data...

My question is how do I get the 2nd bean to be aware of the DB connection in the first bean ?

Thanks for any advice in advance.

Dave
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first, i assume that you already aware that you are using a 'page scope' bean which means it can only be accesed from the same page.
second, in order to have a second bean that can refer to the first bean, you should use both of the bean at the same page
third, in the second bean you should have at least 1 bean property (function) which has parameter related to the first bean, for example :
<jsp:usebean="first"......scope="page"/>
<jsp:usebean="second"......scope="page"/>
<%
Connection con = first.getConnection(); /* assume this bean return a connection named con */
/*assume we want to retrieve data with a select query written in the function getData int second bean property, which will be like, for instance : private ResultSet getData(Connection c).....*/
ResultSet rs = second.getData(con);
...
...
...
well that's all i can say, hope it helps and if there's any blur about my explanation just ask i'll be around OK?
regards
%>
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Thannks for the reply. I see there will still be the need of scripting there, I wont be able to get away with just using EL I dont think.
Hmmm
 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Want Dependency Injection?
Hehe!
 
reply
    Bookmark Topic Watch Topic
  • New Topic