Michael Gerdau wrote:
> [scriptlets to execute JDBC inside a JSP]
>
> >I'm working on adding metadata and other convenience methods now. I'll
> >post the working example soon. Just wondering what similar solutions
> >others might have found to handling JDBC queries within Struts.
>
> The design I us works like this:
> - for each logical item of data write a trivial class with all the
> get/set methods (the Entity class).
If we have any XSLT gurus in our midst, this sounds like it is something that
could be auto-generated from an XML-based description of the "logical item", no?
>
> - for each such trivial data class write a likewise trivial class that
> does know how to map a ResultSet to the Entity class. Some SQL-Stmt
> merging code is added as well to tune the query (the Retriever class).
As above, could such a "trivial" class be auto-generated?
>
> - for each logical query add a more or less trivial class that does the
> actual JDBC stuff (the Controller class).
>
The EJB analogue for this would be to add a finder method that implemented the
logical query.
>
> For all of the above there exists base classes that make writing the
> code very simple.
>
> The Entity class can easily be exposed to Struts and used there.
>
> Th Controller class is invoked from Action; if there is some initialization
> to be done for a JSP create an action that's executed before the JSP is
> actually displayed.
>
> AFAICT the design outlined above does facilitate a better separation
> between the underlying physical data model and the way this data is
> represented to the user than can be achieved by using scriplets.
>
> If anyone is interested I'd be willing to share the code (though I'd
> have to check on copyright before).
>
I'd like to see design patterns like this available to the Struts community --
*especially* if we can create some tools that reduce the tedium of creating
"trivial" classes.
>
> Best,
> Michael
Craig McClanahan