Craig R. McClanahan wrote:

Philipp Röthl wrote:

That's not really what I would like to do.

public ActionForward
      execute(ActionMapping mapping,
              ActionForm form,
              HttpServletRequest request,
              HttpServletResponse response) throws Exception
{
   SomeBean  myBean = new SomeBean();
}


public class SomeBean() {

public SomeBean()
{
//how do I get the Struts DS here - without passing it as an attribute?
}


}

Any hints?




Short answer -- you don't.


The Struts data source isn't magical -- it's an object like any other object, and in order for a method in some bean to talk to an instance, the method needs a reference to that object. Typically, that means you need to pass it in as a method parameter, make it visible through some static getter or factory method, or make it visible in some global repository that is available to the bean instance.

Using JNDI-based data sources is an example of the third approach. Indeed, that is one of the main reasons that using JNDI data sources should be preferred to using the one provided by Struts -- your method inside SomeBean can ask for the data source whenever it needs to, without having to pass it around. (There are other advantages as well, but this is the one most relevant to your concern here.)

So, when ever you neet a datasource, the method in SomeBean will have to search it in JNDI. Doesn't this pose a performance penalty?



phi



Craig



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to