Scott,

In your Action object, get your DataSource using the call to
servlet.getServletContext()..., and then pass the DataSource to your
JavaBean object where you allocate your connection.  This way you avoid
tying your JavaBean to the web application, and also remove the business
logic from your Action.

Hope that helps,

Karen

-----Original Message-----
From: Scott Watson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 01, 2001 6:16 AM
To: Struts Users Mailing List
Subject: Struts Configuration problem


I am trying to design an application using the Struts framework, however, I
have come across some contradicting information in the
documentation and was wondering what is the right way of implementing my
design.

Suppose I have a Action object that calls a JavaBean to perform some
business logic returning a recordset to the action object.  The
action object can then take this recordset save it in the appropriate scope
for the request and forward it onto the view to display
the results.  (At least this is what I have understood of the Struts
framework)

My problem is with the following statement, found in the User's Guide.

Section 1.3  ....an action object should pass the request to another object,
usually a JavaBean. To allow resuse on other platforms,
business-logic JavaBeans should not refer to any Web application objects.
The action object should translate needed details from the
HTTP request and pass those along to the business-logic beans as regular
Java variables....

Now in the Developers Guide under the section for Connection Pooling I found
the following.

    DataSource dataSource = (DataSource)
      servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
    conn = dataSource.getConnection();
    ... perform required functions as in the previous example ...
    conn.close();


If this getConnection code was in my JavaBean then I have tied the JavaBean
to a web application object specifically the
servlet.getServletContext() which is a no-no.

Would I be better to allocate my connection in my Action object and then
either set it or pass it in to my JavaBean object.  What
have people done to handle this situation.


Thanks
Scott Watson.


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

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

Reply via email to