I am trying to use <xe:jdbcConnectionManager>
with <xe:jdbcRowSet>
. Should this work? The book (XPages Extension Library) seems to imply it should, but the example NSF (XPagesJDBC.nsf) does not contain any examples with that combination. Of course, the jdbcRowSet accepts connectionManager
attribute.
I get this error:
com.ibm.xsp.FacesExceptionEx: Unknown ConnectionManager jdbcConnectionManager1
com.ibm.xsp.extlib.util.JdbcUtil.createManagedConnection(JdbcUtil.java:106)
com.ibm.xsp.extlib.jdbc.model.JdbcRowSetAccessor.findConnection(JdbcRowSetAccessor.java:467)
EXTLIB CODE
The problem seems to be in JdbcUtil.java function findConnectionManager(). It returns null and that's why I get the above exception. Here's the function:
public static IJdbcConnectionManager findConnectionManager(FacesContext context, UIComponent from, String name) throws SQLException {
UIComponent c = FacesUtil.getComponentFor(from, name);
if(c!=null) {
return (IJdbcConnectionManager)c;
}
return null;
}
The parameter name
is not null since it is referenced in the exception message. The parameter context
is not used at all. And the parameter from
, if null, is acquired like this (on row 102): from = context.getViewRoot();
.
Here's the function throwing the exception:
public static Connection createManagedConnection(FacesContext context, UIComponent from, String name) throws SQLException {
if(from==null) {
from = context.getViewRoot(); // ROW 102
}
IJdbcConnectionManager manager = findConnectionManager(context, from, name);
if(manager==null) {
throw new FacesExceptionEx(null,"Unknown ConnectionManager {0}",name); // ROW 106
}
return manager.getConnection();
}
MY CODE
So, this works:
<xp:this.data>
<xe:jdbcRowSet var="jdbcRowSet1" maxRows="10"
sqlQuery="SELECT * FROM test.reportcode;"
connectionName="mysql_pooled">
</xe:jdbcRowSet>
</xp:this.data>
And this doesn't work:
<xe:jdbcConnectionManager id="jdbcConnectionManager1"
connectionName="mysql_pooled">
</xe:jdbcConnectionManager>
<xp:this.data>
<xe:jdbcRowSet var="jdbcRowSet1" maxRows="10"
sqlQuery="SELECT * FROM test.reportcode;"
connectionManager="jdbcConnectionManager1">
</xe:jdbcRowSet>
</xp:this.data>
Note that the connectionName is identical, and works perfectly when used directly by jdbcRowSet. The only change is replacing that attribute with a reference to jdbcConnectionManager using that same connectionName. The setup works also perfectly with the jdbcQuery datasource.
How can I make this work? Or can it be done?