Re: facelets & jdbc (homework)
 
On Apr 16, 12:53 am, Thufir <hawat.thu...@gmail.com> wrote:
I don't see much information on using facelets with JDBC.   I have a
managed bean which connects to the db.  Without adding libraries,
what's a good approach to the connection?  I was thinking of putting
the connection parameters in web.xml, for instance, but without a
servlet how would the bean read the context parameters?  Or, is that
reasonable?  Else, putting the parameters at least in a resource
bundle, or a serialized xml class, perhaps.
I'd prefer web.xml, but without a servlet don't know how to read the
parameters.
If you're running facelets, then you have a servlet.
You set up a data source with the <Resource> tag in the context (e.g.,
the "context.xml" descriptor) and the deployment descriptor ("web.xml"
<resource-ref> tag) and retrieve it programmatically along the lines
of (Tomcat configuration):
        final DataSource ds;
        try
        {
            final Context ctx = (Context) new
InitialContext().lookup( "java:/comp/env");
            ds = (DataSource) ctx.lookup( "jdbc/data" ); // "jdbc/
data" is the name from the <Resource>
        }
        catch ( NamingException nex )
        {
            final String msg = "Unable to locate data source: "
                + nex.getLocalizedMessage();
            logger.error( msg, nex );
            throw new IllegalStateException( msg, nex );
        }
as documented at
<http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-
howto.html>
You should spend a significant amount of your study time strengthening
your google-fu.  I recommend randomly reading relevant articles for
about an hour a day.  The Tomcat docs, the Sun Java EE tutorials, and
various articles on <http://www.ibm.com/developerworks/java/> are good
places to begin.
--
Lew