dev@woodstock.java.net

Problems with MySQL-Database-connection with a Visual Web JSF Portlet Page

From: melly_ <melly.kir_at_gmail.com>
Date: Thu, 20 Nov 2008 03:27:34 -0800 (PST)

Hello everybody,

I have a problem with my Netbeans-project. My English is not that good, but
I will try to explain it detailed.


I have a Web-application (Server: OpenPortal Portlet Container) without
Frameworks. I added a ‚Visual Web JSF Portlet Page‘ View.jsp.
I want to use a Woodstock-component–table und I want to fill it with data
from a MySQL-database. I work with Netbeans.


My problem is, that the table in the portlet is shown with the right
column-names, but the data in the fields isn’t there.


My strategy:

1. New Web-application (Server: OpenPortal Portlet Container) without
Frameworks. I added a ‚Visual Web JSF Portlet Page‘ View.jsp.


2. Right klick on the Projekt – New – Other – Glassfish -- JDBC Resource --
Create new JDBC Resource , I retained all presettings, I only picked the
database (‚Extract from Existing Connection‘)

I clicked OK and the sun-resources.xml was created:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application
Server 9.0 Resource Definitions //EN"
"http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
  <jdbc-resource enabled="true" jndi-name="jdbc/kalender_MySQL"
object-type="user" pool-name="connectionPool">
    <description/>
  </jdbc-resource>
  <jdbc-connection-pool allow-non-component-callers="false"
associate-with-thread="false" connection-creation-retry-attempts="0"
connection-creation-retry-interval-in-seconds="10"
connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0"
connection-validation-method="auto-commit"
datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
fail-all-connections="false" idle-timeout-
in-seconds="300" is-connection-validation-required="false"
is-isolation-level-guaranteed="true" lazy-connection-association="false"
lazy-connection-enlistment="false" match-connections="false"
max-connection-usage-count="0" max-pool-size="32"
max-wait-time-in-millis="60000" name="connectionPool"
non-transactional-connections="false" pool-resize-quantity="2"
res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1"
steady-pool-size="8" validate-atmost-once-period-in-seconds="0"
wrap-jdbc-objects="false">
    <property name="URL" value="jdbc:mysql://localhost:3306/kalender"/>
    <property name="User" value="root"/>
    <property name="Password" value="admin"/>
  </jdbc-connection-pool>
</resources>



3. In the web.xml I added a ‚Resource References‘:

Code:
<resource-ref>
        <res-ref-name>jdbc/kalender_MySQL</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>


4. In the SessionBean1.java I added following Code:

Code:
  private void _init() throws Exception {
       
termineRowSet.setDataSourceName("java:comp/env/jdbc/kalender_MySQL");
        termineRowSet.setCommand("SELECT * FROM termine");
        termineRowSet.setTableName("termine");
    }
    private CachedRowSetXImpl termineRowSet = new CachedRowSetXImpl();

    public CachedRowSetXImpl getTermineRowSet() {
        return termineRowSet;
    }

    public void setTermineRowSet(CachedRowSetXImpl crsxi) {
        this.termineRowSet = crsxi;
    }



5. Then I dropped a Woodstock-table on the design-view of the View.jsp and I
added following code in the View.java:

Code:
  private void _init() throws Exception {
        termineDataProvider.setCachedRowSet((javax.sql.rowset.CachedRowSet)
getValue("#{SessionBean1.termineRowSet}"));
    }
  
    private CachedRowSetDataProvider termineDataProvider = new
CachedRowSetDataProvider();

    public CachedRowSetDataProvider getTermineDataProvider() {
        return termineDataProvider;
    }

    public void setTermineDataProvider(CachedRowSetDataProvider crsdp) {
        this.termineDataProvider = crsdp;
    }



6. Then right click at the table, I picked ‚Table Layout‘ from the
appearance list and then I picked the ‚termineDataProvider‘ from the
dropdownlist. Now the columnnames of the MySQL-table are shown in the table
in the Design-view of View.jsp.

When I start the Project, the Portlet is shown in the OpenPortal Portlet
Container and the right columnnames are also displayed, but the table-fields
don’t show up and there is written: “no Elements found”



I tried exactly the same with the Glassfish-Server and a “Visual Web JSF
Page” (no Portlet Page) and it works fine, all data is shown in the table.


I also tried exactly the same with the Tomcat-Server and a “Visual Web JSF
Page”, but there I had to add following code in the context.xml, otherwise
the table isn’t shown at all:

Code:
<Resource auth="Container" driverClassName="com.mysql.jdbc.Driver"
maxActive="20" maxIdle="10" maxWait="-1" name="jdbc/kalender_MySQL"
password="admin" type="javax.sql.DataSource"
url="jdbc:mysql://localhost:3306/kalender" username="root"/>

I recognized that before I added the code in the context.xml, in the
Projects-Window (in Netbeans) under ‚Data Source References‘ the
‚kalender_MySQL‘ is shown, but when I open the properties, the URL is emty.

Only when I add the code in the context.xml, the URL-property is there:
‚jdbc:mysql://localhost:3306/kalender‘. When I use Glassfish, the URL is in
the properties immediately after I do the steps 1 to 6.

In the project with the OpenPortal Portlet Container the URL isn’t shown in
the properties of ‚ kalender_MySQL‘ in the ‘Data Source References‘ at all.


Have anybody any idea what I do wrong? Thanks a lot!

Greetings Melly


-- 
View this message in context: http://www.nabble.com/Problems-with-MySQL-Database-connection-with-a-Visual-Web-JSF-Portlet-Page-tp20599260p20599260.html
Sent from the Project Woodstock - Dev mailing list archive at Nabble.com.