You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Kurt Edegger <ne...@edegger.com> on 2005/12/02 10:24:37 UTC

naming conventions in faces-config.xml

Hi,

I do have a question relating to properties of managed beans defined in 
faces-config.xml. I do face the following situation of two beans:

<managed-bean>
   <managed-bean-name>jdbcDataSourceBean</managed-bean-name>
   <managed-bean-class>JDBCDataSource</managed-bean-class>
   <managed-bean-scope>application</managed-bean-scope>
</managed-bean>

<managed-bean>
   <managed-bean-name>casesDAOBean</managed-bean-name>
   <managed-bean-class>CasesJdbcDAO</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
   <managed-property>
   	<!--  [1] -->
     	<property-name>ds</property-name>
     	<value>#{jdbcDataSourceBean}</value>
   </managed-property>
</managed-bean>

The first bean is injected into the second one and everything works 
fine, but as I wrote the code I decided to name the managed-property of 
the second bean 'dataSource' since it's more descriptive.
I renamed the field in the class and the setter as well.
But when the casesDAOBean is contructed at runtime, the application 
crashes with an exception 'javax.servlet.jsp.el.ELException: Attempt to 
coerce a value of type "JDBCDataSource" to type "javax.sql.DataSource"'.

Somehow the property name is recognized as type, even I had to declared 
it in CasesJdbcDAO anyway (JDBCDataSource dataSource; ).

Why am I not allowed to call the field like a class in the package 
javax.sql?

I had a hard time to find this one, since I wouldn't think of simply 
renaming the field solved the issue.
Any clues why this happens?

Thanks,

	Kurt

P.S.: Yep, sorry, not really myfaces related ;)

Re: naming conventions in faces-config.xml

Posted by Kurt Edegger <ne...@edegger.com>.
Hi Mike,

thank you for your response.

on 12/2/2005 7:30 AM Mike Kienenberger stated:
 > Can you post the setter method for ds in CasesJdbcDAO?

Here are the crucial parts of CasesJdbcDAO:
/* the field definition [1]*/
private JDBCDataSource ds;

/* the setter*/
public void setDs(JDBCDataSource dataSource) {
   this.ds = dataSource;
   this.setDataSource(this.ds.getDs());
}

 > Also can you post the class definition line for JDBCDataSource?
The JDBCDataSource class is very simple and just holds an 
javax.sql.DataSource object. Here are the interesting parts:

/*the class definition */
public class JDBCDataSource{
	
	/*the javax.sql.DataSource*/
	private DataSource ds;
	private String jndiLookup;
...
	
	public DataSource getDs() {
		doLookup();
		return ds;
	}

}


The issue again: If I change the name of the field in CasesJdbcDAO at 
position [1] to dataSource, and adjust the injection in faces-config.xml 
accordingly the application crashes with the stated exception.

Any ideas?

	Kurt



> 
> The question is can JDBCDataSource be coerced to the type of getDs()?
> 
> On 12/2/05, Kurt Edegger <ne...@edegger.com> wrote:
> 
>>Hi,
>>
>>I do have a question relating to properties of managed beans defined in
>>faces-config.xml. I do face the following situation of two beans:
>>
>><managed-bean>
>>   <managed-bean-name>jdbcDataSourceBean</managed-bean-name>
>>   <managed-bean-class>JDBCDataSource</managed-bean-class>
>>   <managed-bean-scope>application</managed-bean-scope>
>></managed-bean>
>>
>><managed-bean>
>>   <managed-bean-name>casesDAOBean</managed-bean-name>
>>   <managed-bean-class>CasesJdbcDAO</managed-bean-class>
>>   <managed-bean-scope>session</managed-bean-scope>
>>   <managed-property>
>>        <!--  [1] -->
>>        <property-name>ds</property-name>
>>        <value>#{jdbcDataSourceBean}</value>
>>   </managed-property>
>></managed-bean>
>>
>>The first bean is injected into the second one and everything works
>>fine, but as I wrote the code I decided to name the managed-property of
>>the second bean 'dataSource' since it's more descriptive.
>>I renamed the field in the class and the setter as well.
>>But when the casesDAOBean is contructed at runtime, the application
>>crashes with an exception 'javax.servlet.jsp.el.ELException: Attempt to
>>coerce a value of type "JDBCDataSource" to type "javax.sql.DataSource"'.
>>
>>Somehow the property name is recognized as type, even I had to declared
>>it in CasesJdbcDAO anyway (JDBCDataSource dataSource; ).
>>
>>Why am I not allowed to call the field like a class in the package
>>javax.sql?
>>
>>I had a hard time to find this one, since I wouldn't think of simply
>>renaming the field solved the issue.
>>Any clues why this happens?
>>
>>Thanks,
>>
>>        Kurt
>>
>>P.S.: Yep, sorry, not really myfaces related ;)
>>


Re: naming conventions in faces-config.xml

Posted by Mike Kienenberger <mk...@gmail.com>.
Oops.  I hadn't realized that we'd moved off the mailing list to private email.
Yes, the problem is that he has superclass methods for get/setDataSource.

---------- Forwarded message ----------
From: Mike Kienenberger <mk...@gmail.com>
Date: Dec 5, 2005 10:12 PM
Subject: Re: naming conventions in faces-config.xml
To: "mail@edegger.com" <ma...@edegger.com>


Aha!

You've changed the name of the method.

Is there already a get/setDataSource(javax.sql.DataSource) method
defined in the superclass?  There must be because you're calling it
from this method!   So there's no way for JSF to know which one to
use.   I'm guessing it's using the one which has a defined getter.
The problem might go away if you create a matching getter...then
again, it might not.

The safest solution is to not overload the getDataSource method and
use getJDBCDataSource (or getDs) instead.

On 12/5/05, mail@edegger.com <ma...@edegger.com> wrote:
> Mike,
>
> thank you for your patience and effort trying to resolve this issue.
> I just changed the essential parts to reproduce the error.
> Here's the setter in CasesJdbcDAO:
>
> public void setDataSource(JDBCDataSource dataSource) {
>   if (log.isDebugEnabled()) log.debug("setting dataSource in casesDAO");
>   this.ds = dataSource;
>   //the dataSource has to be updated after the bean has been injected
>   this.setDataSource(this.ds.getDs());
> }
>
> and the correlating snipplet of the faces-config.xml configuration file:
> <managed-bean>
>   <description>this one retrieves the cases</description>
>   <managed-bean-name>casesDAOBean</managed-bean-name>
>
> <managed-bean-class>com.edegger.dao.springJDBC.CasesJdbcDAO</managed-bean-class>
>   <managed-bean-scope>session</managed-bean-scope>
>   <managed-property>
>     <property-name>dataSource</property-name>
>     <value>#{jdbcDataSourceBean}</value>
>   </managed-property>
> </managed-bean>
>
> Since the field ds is only used within the class CasesJdbcDAO, I don't need an
> getter for this property.
> And finally the signature of the class is:
>
> public class CasesJdbcDAO extends JdbcDaoSupport implements CasesDAO {
>
> whereas CasesDAO is the interface defining a methode to get all the cases as a
> list.
> With this configuration, I'm getting the 'javax.servlet.jsp.el.ELException:
> Attempt to coerce a value of type "com.edegger.dao.springJDBC.JDBCDataSource"
> to type "javax.sql.DataSource"' exception.
>
> To get rid off this exception, I'll need to apply the following chances:
>
> public void setDs(JDBCDataSource dataSource) {
>   if (log.isDebugEnabled()) log.debug("setting dataSource in casesDAO");
>   this.ds = dataSource;
>   //the dataSource has to be updated after the bean has been injected
>   this.setDataSource(this.ds.getDs());
> }
>
> and the correlating snipplet of the faces-config.xml configuration file:
> <managed-bean>
>   <description>this one retrieves the cases</description>
>   <managed-bean-name>casesDAOBean</managed-bean-name>
>
> <managed-bean-class>com.edegger.dao.springJDBC.CasesJdbcDAO</managed-bean-class>
>   <managed-bean-scope>session</managed-bean-scope>
>   <managed-property>
>     <property-name>ds</property-name>
>     <value>#{jdbcDataSourceBean}</value>
>   </managed-property>
> </managed-bean>
>
> The signature stays the same.
>
> I know something's not adding up - but I can't explain it.
>
> Enjoy,
>
>   Kurt
>
>
>
>
> Quoting Mike Kienenberger <mk...@gmail.com>:
>
> > Kurt, what does both your setter and getter code and method signatures
> > look like on CasesJdbcDAO when you're getting this error?
> >
> > 'javax.servlet.jsp.el.ELException: Attempt to coerce a value of type
> > "JDBCDataSource" to type "javax.sql.DataSource"' indicates an attempt
> > to inject a JDBCDataSource into a value binding expecting a
> > javax.sql.DataSource.
> >
> > Something's not adding up here.
> >
> > On 12/5/05, Kurt Edegger <ma...@edegger.com> wrote:
> > > Hi Mike,
> > >
> > > thank you for your help, but I don't think that your answer is correct.
> > > We are talking about two different classes. The first one is
> > > CasesJdbcDAO with the setter taking an JDBCDataSource Object and the
> > > second on is the JDBCDataSource class having a getDs() method to return
> > > the actual javax.sql.DataSource object. To clearify: The JDBCDataSource
> > > object is injected to CasesJdbcDAO using the setter in CasesJdbcDAO
> > > which takes the correct type of JDBCDataSource.
> > > I don't think this is an issue of a misscasted type since it works if
> > > the field in CasesJdbcDAO (marked as [1] in my former postings) isn't
> > > named 'dataSource'. In that case the JSF implementation seems to
> > > interpret the name as a type and causing the exception. In the case it
> > > isn't named 'dataSource' (e.g. 'ds' in my example) the injection is done
> > > without any problems.
> > >
> > > I'm appreciating your help and thoughts.
> > >
> > > Kurt
> > >
> > >
> > >
> > > on 12/5/2005 8:54 AM Mike Kienenberger stated:
> > > > Your setter and getter return different types.
> > > >
> > > >  public DataSource getDs()
> > > >
> > > > needs to be
> > > >
> > > >  public JDBCDataSource getDs() {
> > > >
> > > > On 12/2/05, Kurt Edegger <ne...@edegger.com> wrote:
> > > >
> > > >>Hi Mike,
> > > >>
> > > >>thank you for your response.
> > > >>
> > > >>on 12/2/2005 7:30 AM Mike Kienenberger stated:
> > > >> > Can you post the setter method for ds in CasesJdbcDAO?
> > > >>
> > > >>Here are the crucial parts of CasesJdbcDAO:
> > > >>/* the field definition [1]*/
> > > >>private JDBCDataSource ds;
> > > >>
> > > >>/* the setter*/
> > > >>public void setDs(JDBCDataSource dataSource) {
> > > >>   this.ds = dataSource;
> > > >>   this.setDataSource(this.ds.getDs());
> > > >>}
> > > >>
> > > >> > Also can you post the class definition line for JDBCDataSource?
> > > >>The JDBCDataSource class is very simple and just holds an
> > > >>javax.sql.DataSource object. Here are the interesting parts:
> > > >>
> > > >>/*the class definition */
> > > >>public class JDBCDataSource{
> > > >>
> > > >>     /*the javax.sql.DataSource*/
> > > >>     private DataSource ds;
> > > >>     private String jndiLookup;
> > > >>...
> > > >>
> > > >>     public DataSource getDs() {
> > > >>         doLookup();
> > > >>         return ds;
> > > >>     }
> > > >>
> > > >>}
> > > >>
> > > >>
> > > >>The issue again: If I change the name of the field in CasesJdbcDAO at
> > > >>position [1] to dataSource, and adjust the injection in faces-config.xml
> > > >>accordingly the application crashes with the stated exception.
> > > >>
> > > >>Any ideas?
> > > >>
> > > >>     Kurt
> > > >>
> > >
> > >
> >
>
>
>
>
>


On 12/5/05, Simon Kitching <sk...@obsidium.com> wrote:
> mail@edegger.com wrote:
> > Mike,
> >
> > thank you for your patience and effort trying to resolve this issue.
> > I just changed the essential parts to reproduce the error.
> > Here's the setter in CasesJdbcDAO:
> >
> > public void setDataSource(JDBCDataSource dataSource) {
> >   if (log.isDebugEnabled()) log.debug("setting dataSource in casesDAO");
> >   this.ds = dataSource;
> >   //the dataSource has to be updated after the bean has been injected
> >   this.setDataSource(this.ds.getDs());
> > }
> >
> > and the correlating snipplet of the faces-config.xml configuration file:
> > <managed-bean>
> >   <description>this one retrieves the cases</description>
> >   <managed-bean-name>casesDAOBean</managed-bean-name>
> >
> > <managed-bean-class>com.edegger.dao.springJDBC.CasesJdbcDAO</managed-bean-class>
> >   <managed-bean-scope>session</managed-bean-scope>
> >   <managed-property>
> >     <property-name>dataSource</property-name>
> >     <value>#{jdbcDataSourceBean}</value>
> >   </managed-property>
> > </managed-bean>
> >
> > Since the field ds is only used within the class CasesJdbcDAO, I don't need an
> > getter for this property.
> > And finally the signature of the class is:
> >
> > public class CasesJdbcDAO extends JdbcDaoSupport implements CasesDAO {
> >
>
> Just as a guess, you don't have any methods on the base classes that
> have similar names or signatures do you? eg:
>
> class JdbcDaoSupport {
>    public void setDataSource(...);
> }
>
>
> Regards,
>
> Simon
>

Re: naming conventions in faces-config.xml

Posted by Simon Kitching <sk...@obsidium.com>.
mail@edegger.com wrote:
> Mike,
> 
> thank you for your patience and effort trying to resolve this issue.
> I just changed the essential parts to reproduce the error.
> Here's the setter in CasesJdbcDAO:
> 
> public void setDataSource(JDBCDataSource dataSource) {
>   if (log.isDebugEnabled()) log.debug("setting dataSource in casesDAO");
>   this.ds = dataSource;
>   //the dataSource has to be updated after the bean has been injected
>   this.setDataSource(this.ds.getDs());
> }
> 
> and the correlating snipplet of the faces-config.xml configuration file:
> <managed-bean>
>   <description>this one retrieves the cases</description>
>   <managed-bean-name>casesDAOBean</managed-bean-name>
>  
> <managed-bean-class>com.edegger.dao.springJDBC.CasesJdbcDAO</managed-bean-class>
>   <managed-bean-scope>session</managed-bean-scope>
>   <managed-property>
>     <property-name>dataSource</property-name>
>     <value>#{jdbcDataSourceBean}</value>
>   </managed-property> 
> </managed-bean>
> 
> Since the field ds is only used within the class CasesJdbcDAO, I don't need an
> getter for this property.
> And finally the signature of the class is:
> 
> public class CasesJdbcDAO extends JdbcDaoSupport implements CasesDAO {
> 

Just as a guess, you don't have any methods on the base classes that 
have similar names or signatures do you? eg:

class JdbcDaoSupport {
   public void setDataSource(...);
}


Regards,

Simon

Re: naming conventions in faces-config.xml

Posted by ma...@edegger.com.
Mike,

thank you for your patience and effort trying to resolve this issue.
I just changed the essential parts to reproduce the error.
Here's the setter in CasesJdbcDAO:

public void setDataSource(JDBCDataSource dataSource) {
  if (log.isDebugEnabled()) log.debug("setting dataSource in casesDAO");
  this.ds = dataSource;
  //the dataSource has to be updated after the bean has been injected
  this.setDataSource(this.ds.getDs());
}

and the correlating snipplet of the faces-config.xml configuration file:
<managed-bean>
  <description>this one retrieves the cases</description>
  <managed-bean-name>casesDAOBean</managed-bean-name>
 
<managed-bean-class>com.edegger.dao.springJDBC.CasesJdbcDAO</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
    <property-name>dataSource</property-name>
    <value>#{jdbcDataSourceBean}</value>
  </managed-property> 
</managed-bean>

Since the field ds is only used within the class CasesJdbcDAO, I don't need an
getter for this property.
And finally the signature of the class is:

public class CasesJdbcDAO extends JdbcDaoSupport implements CasesDAO {

whereas CasesDAO is the interface defining a methode to get all the cases as a
list.
With this configuration, I'm getting the 'javax.servlet.jsp.el.ELException:
Attempt to coerce a value of type "com.edegger.dao.springJDBC.JDBCDataSource"
to type "javax.sql.DataSource"' exception.

To get rid off this exception, I'll need to apply the following chances:

public void setDs(JDBCDataSource dataSource) {
  if (log.isDebugEnabled()) log.debug("setting dataSource in casesDAO");
  this.ds = dataSource;
  //the dataSource has to be updated after the bean has been injected
  this.setDataSource(this.ds.getDs());
}

and the correlating snipplet of the faces-config.xml configuration file:
<managed-bean>
  <description>this one retrieves the cases</description>
  <managed-bean-name>casesDAOBean</managed-bean-name>
 
<managed-bean-class>com.edegger.dao.springJDBC.CasesJdbcDAO</managed-bean-class>
  <managed-bean-scope>session</managed-bean-scope>
  <managed-property>
    <property-name>ds</property-name>
    <value>#{jdbcDataSourceBean}</value>
  </managed-property> 
</managed-bean>

The signature stays the same.

I know something's not adding up - but I can't explain it.

Enjoy,

  Kurt




Quoting Mike Kienenberger <mk...@gmail.com>:

> Kurt, what does both your setter and getter code and method signatures
> look like on CasesJdbcDAO when you're getting this error?
> 
> 'javax.servlet.jsp.el.ELException: Attempt to coerce a value of type
> "JDBCDataSource" to type "javax.sql.DataSource"' indicates an attempt
> to inject a JDBCDataSource into a value binding expecting a
> javax.sql.DataSource.
> 
> Something's not adding up here.
> 
> On 12/5/05, Kurt Edegger <ma...@edegger.com> wrote:
> > Hi Mike,
> >
> > thank you for your help, but I don't think that your answer is correct.
> > We are talking about two different classes. The first one is
> > CasesJdbcDAO with the setter taking an JDBCDataSource Object and the
> > second on is the JDBCDataSource class having a getDs() method to return
> > the actual javax.sql.DataSource object. To clearify: The JDBCDataSource
> > object is injected to CasesJdbcDAO using the setter in CasesJdbcDAO
> > which takes the correct type of JDBCDataSource.
> > I don't think this is an issue of a misscasted type since it works if
> > the field in CasesJdbcDAO (marked as [1] in my former postings) isn't
> > named 'dataSource'. In that case the JSF implementation seems to
> > interpret the name as a type and causing the exception. In the case it
> > isn't named 'dataSource' (e.g. 'ds' in my example) the injection is done
> > without any problems.
> >
> > I'm appreciating your help and thoughts.
> >
> > Kurt
> >
> >
> >
> > on 12/5/2005 8:54 AM Mike Kienenberger stated:
> > > Your setter and getter return different types.
> > >
> > >  public DataSource getDs()
> > >
> > > needs to be
> > >
> > >  public JDBCDataSource getDs() {
> > >
> > > On 12/2/05, Kurt Edegger <ne...@edegger.com> wrote:
> > >
> > >>Hi Mike,
> > >>
> > >>thank you for your response.
> > >>
> > >>on 12/2/2005 7:30 AM Mike Kienenberger stated:
> > >> > Can you post the setter method for ds in CasesJdbcDAO?
> > >>
> > >>Here are the crucial parts of CasesJdbcDAO:
> > >>/* the field definition [1]*/
> > >>private JDBCDataSource ds;
> > >>
> > >>/* the setter*/
> > >>public void setDs(JDBCDataSource dataSource) {
> > >>   this.ds = dataSource;
> > >>   this.setDataSource(this.ds.getDs());
> > >>}
> > >>
> > >> > Also can you post the class definition line for JDBCDataSource?
> > >>The JDBCDataSource class is very simple and just holds an
> > >>javax.sql.DataSource object. Here are the interesting parts:
> > >>
> > >>/*the class definition */
> > >>public class JDBCDataSource{
> > >>
> > >>     /*the javax.sql.DataSource*/
> > >>     private DataSource ds;
> > >>     private String jndiLookup;
> > >>...
> > >>
> > >>     public DataSource getDs() {
> > >>         doLookup();
> > >>         return ds;
> > >>     }
> > >>
> > >>}
> > >>
> > >>
> > >>The issue again: If I change the name of the field in CasesJdbcDAO at
> > >>position [1] to dataSource, and adjust the injection in faces-config.xml
> > >>accordingly the application crashes with the stated exception.
> > >>
> > >>Any ideas?
> > >>
> > >>     Kurt
> > >>
> >
> >
> 





Re: naming conventions in faces-config.xml

Posted by Mike Kienenberger <mk...@gmail.com>.
Kurt, what does both your setter and getter code and method signatures
look like on CasesJdbcDAO when you're getting this error?

'javax.servlet.jsp.el.ELException: Attempt to coerce a value of type
"JDBCDataSource" to type "javax.sql.DataSource"' indicates an attempt
to inject a JDBCDataSource into a value binding expecting a
javax.sql.DataSource.

Something's not adding up here.

On 12/5/05, Kurt Edegger <ma...@edegger.com> wrote:
> Hi Mike,
>
> thank you for your help, but I don't think that your answer is correct.
> We are talking about two different classes. The first one is
> CasesJdbcDAO with the setter taking an JDBCDataSource Object and the
> second on is the JDBCDataSource class having a getDs() method to return
> the actual javax.sql.DataSource object. To clearify: The JDBCDataSource
> object is injected to CasesJdbcDAO using the setter in CasesJdbcDAO
> which takes the correct type of JDBCDataSource.
> I don't think this is an issue of a misscasted type since it works if
> the field in CasesJdbcDAO (marked as [1] in my former postings) isn't
> named 'dataSource'. In that case the JSF implementation seems to
> interpret the name as a type and causing the exception. In the case it
> isn't named 'dataSource' (e.g. 'ds' in my example) the injection is done
> without any problems.
>
> I'm appreciating your help and thoughts.
>
> Kurt
>
>
>
> on 12/5/2005 8:54 AM Mike Kienenberger stated:
> > Your setter and getter return different types.
> >
> >  public DataSource getDs()
> >
> > needs to be
> >
> >  public JDBCDataSource getDs() {
> >
> > On 12/2/05, Kurt Edegger <ne...@edegger.com> wrote:
> >
> >>Hi Mike,
> >>
> >>thank you for your response.
> >>
> >>on 12/2/2005 7:30 AM Mike Kienenberger stated:
> >> > Can you post the setter method for ds in CasesJdbcDAO?
> >>
> >>Here are the crucial parts of CasesJdbcDAO:
> >>/* the field definition [1]*/
> >>private JDBCDataSource ds;
> >>
> >>/* the setter*/
> >>public void setDs(JDBCDataSource dataSource) {
> >>   this.ds = dataSource;
> >>   this.setDataSource(this.ds.getDs());
> >>}
> >>
> >> > Also can you post the class definition line for JDBCDataSource?
> >>The JDBCDataSource class is very simple and just holds an
> >>javax.sql.DataSource object. Here are the interesting parts:
> >>
> >>/*the class definition */
> >>public class JDBCDataSource{
> >>
> >>     /*the javax.sql.DataSource*/
> >>     private DataSource ds;
> >>     private String jndiLookup;
> >>...
> >>
> >>     public DataSource getDs() {
> >>         doLookup();
> >>         return ds;
> >>     }
> >>
> >>}
> >>
> >>
> >>The issue again: If I change the name of the field in CasesJdbcDAO at
> >>position [1] to dataSource, and adjust the injection in faces-config.xml
> >>accordingly the application crashes with the stated exception.
> >>
> >>Any ideas?
> >>
> >>     Kurt
> >>
>
>

Re: naming conventions in faces-config.xml

Posted by Kurt Edegger <ma...@edegger.com>.
Hi Mike,

thank you for your help, but I don't think that your answer is correct.
We are talking about two different classes. The first one is 
CasesJdbcDAO with the setter taking an JDBCDataSource Object and the 
second on is the JDBCDataSource class having a getDs() method to return 
the actual javax.sql.DataSource object. To clearify: The JDBCDataSource 
object is injected to CasesJdbcDAO using the setter in CasesJdbcDAO 
which takes the correct type of JDBCDataSource.
I don't think this is an issue of a misscasted type since it works if 
the field in CasesJdbcDAO (marked as [1] in my former postings) isn't 
named 'dataSource'. In that case the JSF implementation seems to 
interpret the name as a type and causing the exception. In the case it 
isn't named 'dataSource' (e.g. 'ds' in my example) the injection is done 
without any problems.

I'm appreciating your help and thoughts.

Kurt



on 12/5/2005 8:54 AM Mike Kienenberger stated:
> Your setter and getter return different types.
> 
>  public DataSource getDs()
> 
> needs to be
> 
>  public JDBCDataSource getDs() {
> 
> On 12/2/05, Kurt Edegger <ne...@edegger.com> wrote:
> 
>>Hi Mike,
>>
>>thank you for your response.
>>
>>on 12/2/2005 7:30 AM Mike Kienenberger stated:
>> > Can you post the setter method for ds in CasesJdbcDAO?
>>
>>Here are the crucial parts of CasesJdbcDAO:
>>/* the field definition [1]*/
>>private JDBCDataSource ds;
>>
>>/* the setter*/
>>public void setDs(JDBCDataSource dataSource) {
>>   this.ds = dataSource;
>>   this.setDataSource(this.ds.getDs());
>>}
>>
>> > Also can you post the class definition line for JDBCDataSource?
>>The JDBCDataSource class is very simple and just holds an
>>javax.sql.DataSource object. Here are the interesting parts:
>>
>>/*the class definition */
>>public class JDBCDataSource{
>>
>>     /*the javax.sql.DataSource*/
>>     private DataSource ds;
>>     private String jndiLookup;
>>...
>>
>>     public DataSource getDs() {
>>         doLookup();
>>         return ds;
>>     }
>>
>>}
>>
>>
>>The issue again: If I change the name of the field in CasesJdbcDAO at
>>position [1] to dataSource, and adjust the injection in faces-config.xml
>>accordingly the application crashes with the stated exception.
>>
>>Any ideas?
>>
>>     Kurt
>>


Re: naming conventions in faces-config.xml

Posted by Mike Kienenberger <mk...@gmail.com>.
Your setter and getter return different types.

 public DataSource getDs()

needs to be

 public JDBCDataSource getDs() {

On 12/2/05, Kurt Edegger <ne...@edegger.com> wrote:
> Hi Mike,
>
> thank you for your response.
>
> on 12/2/2005 7:30 AM Mike Kienenberger stated:
>  > Can you post the setter method for ds in CasesJdbcDAO?
>
> Here are the crucial parts of CasesJdbcDAO:
> /* the field definition [1]*/
> private JDBCDataSource ds;
>
> /* the setter*/
> public void setDs(JDBCDataSource dataSource) {
>    this.ds = dataSource;
>    this.setDataSource(this.ds.getDs());
> }
>
>  > Also can you post the class definition line for JDBCDataSource?
> The JDBCDataSource class is very simple and just holds an
> javax.sql.DataSource object. Here are the interesting parts:
>
> /*the class definition */
> public class JDBCDataSource{
>
>      /*the javax.sql.DataSource*/
>      private DataSource ds;
>      private String jndiLookup;
> ...
>
>      public DataSource getDs() {
>          doLookup();
>          return ds;
>      }
>
> }
>
>
> The issue again: If I change the name of the field in CasesJdbcDAO at
> position [1] to dataSource, and adjust the injection in faces-config.xml
> accordingly the application crashes with the stated exception.
>
> Any ideas?
>
>      Kurt
>

Re: naming conventions in faces-config.xml

Posted by Kurt Edegger <ne...@edegger.com>.
Hi Mike,

thank you for your response.

on 12/2/2005 7:30 AM Mike Kienenberger stated:
 > Can you post the setter method for ds in CasesJdbcDAO?

Here are the crucial parts of CasesJdbcDAO:
/* the field definition [1]*/
private JDBCDataSource ds;

/* the setter*/
public void setDs(JDBCDataSource dataSource) {
   this.ds = dataSource;
   this.setDataSource(this.ds.getDs());
}

 > Also can you post the class definition line for JDBCDataSource?
The JDBCDataSource class is very simple and just holds an 
javax.sql.DataSource object. Here are the interesting parts:

/*the class definition */
public class JDBCDataSource{

     /*the javax.sql.DataSource*/
     private DataSource ds;
     private String jndiLookup;
...

     public DataSource getDs() {
         doLookup();
         return ds;
     }

}


The issue again: If I change the name of the field in CasesJdbcDAO at 
position [1] to dataSource, and adjust the injection in faces-config.xml 
accordingly the application crashes with the stated exception.

Any ideas?

     Kurt

Re: naming conventions in faces-config.xml

Posted by Mike Kienenberger <mk...@gmail.com>.
Can you post the setter method for ds in CasesJdbcDAO?
Also can you post the class definition line for JDBCDataSource?

The question is can JDBCDataSource be coerced to the type of getDs()?

On 12/2/05, Kurt Edegger <ne...@edegger.com> wrote:
> Hi,
>
> I do have a question relating to properties of managed beans defined in
> faces-config.xml. I do face the following situation of two beans:
>
> <managed-bean>
>    <managed-bean-name>jdbcDataSourceBean</managed-bean-name>
>    <managed-bean-class>JDBCDataSource</managed-bean-class>
>    <managed-bean-scope>application</managed-bean-scope>
> </managed-bean>
>
> <managed-bean>
>    <managed-bean-name>casesDAOBean</managed-bean-name>
>    <managed-bean-class>CasesJdbcDAO</managed-bean-class>
>    <managed-bean-scope>session</managed-bean-scope>
>    <managed-property>
>         <!--  [1] -->
>         <property-name>ds</property-name>
>         <value>#{jdbcDataSourceBean}</value>
>    </managed-property>
> </managed-bean>
>
> The first bean is injected into the second one and everything works
> fine, but as I wrote the code I decided to name the managed-property of
> the second bean 'dataSource' since it's more descriptive.
> I renamed the field in the class and the setter as well.
> But when the casesDAOBean is contructed at runtime, the application
> crashes with an exception 'javax.servlet.jsp.el.ELException: Attempt to
> coerce a value of type "JDBCDataSource" to type "javax.sql.DataSource"'.
>
> Somehow the property name is recognized as type, even I had to declared
> it in CasesJdbcDAO anyway (JDBCDataSource dataSource; ).
>
> Why am I not allowed to call the field like a class in the package
> javax.sql?
>
> I had a hard time to find this one, since I wouldn't think of simply
> renaming the field solved the issue.
> Any clues why this happens?
>
> Thanks,
>
>         Kurt
>
> P.S.: Yep, sorry, not really myfaces related ;)
>