Hello everyone,
I am new here, I am doing the switch from LAMP to Java and I have being following some examples from the web and Deitel book.

Here is my problem. I am trying to build a simple basic Web App with MySql, Tomcat 6, NetBeans and JSF.
But I can’t get the dataSource to work with the connection pool. Each time I am loading my index.xhtml. I am getting null DataSource.

I need help figuring out what I am missing in my configuration?

Note: I also posted this question on NetBeans Forums - Index.

Here are the configuration details:

Environment: Windown 7, MySQL 5.5.8, Tomcat 6 (both part of Xampp package) and NetBeans 7.0.

Application Folder:
  • Web Pages
  • Index.xhtml
  • META-INF -> context.xml
  • WEB-INF -> web.xml
  • Source Packages
  • webtime
  • DictionaryBean.java
  • Libraries
  • JSF…. (from NetBeans)
  • JDK 1.6 (defaults)
  • MySQL JDBC (I added it)


Configuring the Connection Pool:

Context.xml:
HTML Code:
<?xml version="1.0" encoding="UTF-8"?> 
<Context antiJARLocking="true" path="/WebApp_JSF"> 
<Resource name="jdbc/WebApp_JSF" auth="Container" type="javax.sql.DataSource" 
maxActive="100" maxIdle="30" maxWait="10000" 
username="root" password="22142214" driverClassName="com.mysql.jdbc.Driver" 
url="jdbc:mysql://localhost:3306/dictionary"></Resource> 
</Context> 
Web.xml:
HTML Code:
<resource-ref> 
<description>Dictionary App database</description> 
<res-ref-name>jdbc/WebApp_JSF</res-ref-name> 
<res-type>javax.sql.DataSource</res-type> 
<res-auth>Container</res-auth> 
<res-sharing-scope>Shareable</res-sharing-scope> 
</resource-ref> 
Initiating the dataSource in DictionaryBean.java:
import java.sql.Connection; 
import java.sql.PreparedStatement; 
import java.sql.ResultSet; 
import java.sql.SQLException; 
import javax.annotation.Resource; 
import javax.faces.bean.ManagedBean; 
import javax.sql.DataSource; 
import javax.sql.rowset.CachedRowSet; 
 
@ManagedBean( name="dictionaryBean") 
public class DictionaryBean { 
 
…. (variables) 
 
// allow the server to inject the DataSource 
@Resource(name="jdbc/WebApp_JSF") 
DataSource dataSource; 
 
….(getters and setters) 
 
// return a results set of entries 
public ResultSet getDictionaryDefinitions() throws SQLException 
{ 
 
 
// Check is data source inject into the server 
if(dataSource == null){ 
throw new SQLException ("Unable to obtain DataSource"); 
} 
……..} 
 
(I STOP HERE BECAUSE THE APPLICATION BREAK IN THIS EXCEPTION)
index.xhtml:
HTML Code:
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:h="http://java.sun.com/jsf/html" 
xmlns:f="http://java.sun.com/jsf/core"> 
<h:head> 
</h:head> 
<h:body> 
<h1>Dictionary Definitions</h1> 
<h:form> 
<p><h:commandButton value="Add Definition" action="addDefinition"></h:commandButton></p> 
</h:form> 
<h:dataTable value="#{dictionaryBean.dictionaryDefinitions}" var="definiion" 
cellpadding="5" cellspacing="0"> 
<h:column> 
<f:facet name="header">Word Entry</f:facet> 
#{definiion.ENTRY} 
</h:column> 
<h:column> 
<f:facet name="header">Word Definition</f:facet> 
#{definiion.DEFINITION} 
</h:column> 
</h:dataTable> 
</h:body> 
</html>