I'd suggest that isolating database access in Model components that are
called from the Action class is a more appropriate approach.
What happens if you throw a SQLException in the tag or if you end up
needing to have conditional processing depending on what you bring back
from the database? You'll need conditional logic either in the tag or in
the JSP page to handle this - conditional logic that may be better managed
by the controller (Action class).
Here's an alternative approach:
Form POST ->
Form Bean ->
Action Class ->
Model Component (access database here) ->
Action class stores data from Model in a bean, attaches bean to
PageContext ->
JSP page retrieves data from bean using regular Struts tags
Circumventing this approach by performing database access in a custom tag
requires you to move Exception management and conditional processing from
your Action class into the JSP page - which then eliminates much of the
value of the MVC architecture...
Kevin
-------
Kevin Bedell
Author, Struts Kick Start
http://www.amazon.com/exec/obidos/tg/detail/-/0672324725/qid=1036509916/sr=1-1/ref=sr_1_1/002-7047256-5912803?v=glance
Mike Way <[EMAIL PROTECTED]> on 11/05/2002 06:04:22 AM
Please respond to "Struts Users Mailing List"
<[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
cc: (bcc: Kevin Bedell/Systems/USHO/SunLife)
Subject: Re: accessing DataSource from custom tag
Andrew,
pageContext.getServletContext().getAttribute(....
But, do you really want to do this ?
Mike
At 02:53 05/11/2002 -0800, you wrote:
>is there any way to access the DataSource defined in
>struts-config.xml from within a custom tag.
>
>i usually get it from the ActionServlet context
>attribute Action.DATA_SOURCE_KEY from within an
>Action.
>
>but its not defined in the pageContext of a tag, so i
>assume its not easy to do, though i saw it mentioned,
>but not fully explained, in a thread on this list
>(Subject: RE: Urgent : Any Example which will show
><htlm:select > <html:option> tag).
>
>my goal is to write a simple tag that downloads a list
>of countries from a database table as an ArrayList,
>adds it to the session so i can put it into an
>. if there is a better approach, please let me know. thanks, andrew.
>__________________________________________________ Do you Yahoo!? HotJobs
>- Search new jobs daily now http://hotjobs.yahoo.com/ -- To unsubscribe,
>e-mail: For additional commands, e-mail:
Mike Way,
Senior Consultant, Shared Skills Ltd
+44 (0)1752 491088, mobile +44 (0) 7941 225581
email: [EMAIL PROTECTED] web: www.sharedskills.com
--
To unsubscribe, e-mail: <
mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <
mailto:struts-user-help@;jakarta.apache.org>
---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use
of the individual or entity to which it is addressed and may contain
information that is privileged, proprietary , confidential and exempt from
disclosure. If you are not the intended recipient, you are notified that
any dissemination, distribution or copying of this communication is
strictly prohibited. If you have received this communication in error,
please notify the sender and erase this e-mail message immediately.
---------------------------------------------------------------------------
--
To unsubscribe, e-mail: <mailto:struts-user-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@;jakarta.apache.org>