Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing beans..

 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • 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
 
evan theon
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Eugene Lucash
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Want Dependency Injection?
Hehe!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic