struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Assenza, Chris" <casse...@Accessdc.com>
Subject RE: How to access the Struts ConnectionPool from an ActionForm
Date Thu, 21 Nov 2002 18:39:31 GMT
Steve,

If memory serves, I don't think you can get the ActionServlet (thus the
servlet) from the Form; but it's been a long time since I last looked at
that stuff and I may well be incorrect on that - it's just a guess. 

As for the db call issue, it makes more sense for something like that to be
in a separate class or your Action at the least.  You would simply call the
appropriate accessors on the form to set the results.  For example, if you
had three VARCHAR/TEXT columns you could query  and obtain a ResultSet.
Then, iterate through the ResultSet and set the appropriate form properties.
Obviously, that's just one way to do it and perhaps not the ideal way, but
it is a viable option.  

Chris

-----Original Message-----
From: Steven Citron-Pousty [mailto:Steven.Citron-Pousty@yale.edu]
Sent: Wednesday, November 20, 2002 4:46 PM
To: struts-user
Subject: How to access the Struts ConnectionPool from an ActionForm


Greetings all:
I am trying to populate the options for a select list from a DB call. 
And I am getting a null pointer exception from this line in the 
ActionForm (I copied it from my Action, where it works):

DataSource dataSource = (DataSource) 
servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);

What I am trying to do is use the ConnectionPool provided by Struts. 
This call works great in my Action but doesn't work in my ActionForm.
On the IRC channel (irc.freenode.net #struts) we have been discussing 
the merits of putting a DB call in an ActionForm.

SOoo, my main question is,
How do I ask the context for the connection pool in an ActionForm?

But I would also love to see discussion about the merits of putting a DB 
call in an ActionForm at all. If I didn't put the call in the ActionForm 
how would I get the data from the DB call into the actionForm?

Thanks in advance for all your help,
Steve

BTW it appears as if posting from the basebeans nntp doesn't get posted 
to the list.


--
To unsubscribe, e-mail:
<mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail:
<mailto:struts-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:struts-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-user-help@jakarta.apache.org>


Mime
View raw message