You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by smallufo <sm...@gmail.com> on 2010/12/14 11:45:24 UTC
How to I get an un-proxied Spring Bean ?
I have a page with such definition :
public class CrudPage<T extends Serializable> extends WebPage
{
public CrudPage(PageParameters pps , AbstractDao<T> dao)
{...}
}
and here is how I initialize the page :
CrudPage<User> page = new CrudPage<User>(pps , userDao);
the userDao is a Spring injected DAO :
@SpringBean private UserDao userDao;
And in fact , UserDao extends Abstract Dao Pattern :
public interface UserDao extends AbstractDao<User> {...}
Here comes the problem :
I want to know which type is passed to CrudPage , I use the code :
ParameterizedType genericSuperclass = (ParameterizedType)
dao.getClass().getGenericSuperclass();
this.clazz = (Class<T>) genericSuperclass.getActualTypeArguments()[0];
But it throws exception :
java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
I then print the type :
System.out.println("dao.getClass() = " + dao.getClass());
System.out.println("dao.getClass().getGenericSuperclass() = " +
dao.getClass().getGenericSuperclass());
and found the dao is proxied :
dao.getClass() = class org.apache.wicket.proxy.$Proxy101
dao.getClass().getGenericSuperclass() = class java.lang.reflect.Proxy
Maybe that's why I cannot get the type ...
And ... how to solve the problem ?
Thanks a lot !
Re: How to I get an un-proxied Spring Bean ?
Posted by Igor Vaynberg <ig...@gmail.com>.
keep calling superclass until its not a proxy
-igor
On Tue, Dec 14, 2010 at 3:28 PM, smallufo <sm...@gmail.com> wrote:
> Hi ,
> I tried :
> dao.getClass() = class org.apache.wicket.proxy.$Proxy101
> dao.getClass().getGenericSuperclass() = class java.lang.reflect.Proxy
> dao.getClass().getSuperclass() = class java.lang.reflect.Proxy
>
> But still unable to get the dao class
>
> 2010/12/14 Pedro Santos <pe...@gmail.com>
>
>> proxyClass.getSuperclass() gives you the dao type
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: How to I get an un-proxied Spring Bean ?
Posted by smallufo <sm...@gmail.com>.
Hi ,
I tried :
dao.getClass() = class org.apache.wicket.proxy.$Proxy101
dao.getClass().getGenericSuperclass() = class java.lang.reflect.Proxy
dao.getClass().getSuperclass() = class java.lang.reflect.Proxy
But still unable to get the dao class
2010/12/14 Pedro Santos <pe...@gmail.com>
> proxyClass.getSuperclass() gives you the dao type
>
>
Re: How to I get an un-proxied Spring Bean ?
Posted by Pedro Santos <pe...@gmail.com>.
proxyClass.getSuperclass() gives you the dao type
On Tue, Dec 14, 2010 at 8:45 AM, smallufo <sm...@gmail.com> wrote:
> I have a page with such definition :
>
> public class CrudPage<T extends Serializable> extends WebPage
> {
> public CrudPage(PageParameters pps , AbstractDao<T> dao)
> {...}
> }
>
> and here is how I initialize the page :
> CrudPage<User> page = new CrudPage<User>(pps , userDao);
>
> the userDao is a Spring injected DAO :
> @SpringBean private UserDao userDao;
>
> And in fact , UserDao extends Abstract Dao Pattern :
> public interface UserDao extends AbstractDao<User> {...}
>
> Here comes the problem :
> I want to know which type is passed to CrudPage , I use the code :
>
> ParameterizedType genericSuperclass = (ParameterizedType)
> dao.getClass().getGenericSuperclass();
> this.clazz = (Class<T>) genericSuperclass.getActualTypeArguments()[0];
>
> But it throws exception :
> java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
>
> I then print the type :
> System.out.println("dao.getClass() = " + dao.getClass());
> System.out.println("dao.getClass().getGenericSuperclass() = " +
> dao.getClass().getGenericSuperclass());
>
> and found the dao is proxied :
> dao.getClass() = class org.apache.wicket.proxy.$Proxy101
> dao.getClass().getGenericSuperclass() = class java.lang.reflect.Proxy
>
> Maybe that's why I cannot get the type ...
>
> And ... how to solve the problem ?
>
> Thanks a lot !
>
--
Pedro Henrique Oliveira dos Santos
Re: How to I get an un-proxied Spring Bean ?
Posted by James Carman <ja...@carmanconsulting.com>.
You could also have AbstractDao have a method like this:
public <T> Class<T> getEntityType();
I assume you need the type in your DAO when constructing queries, so
you probably already have that set up somewhere.
On Tue, Dec 14, 2010 at 5:45 AM, smallufo <sm...@gmail.com> wrote:
> I have a page with such definition :
>
> public class CrudPage<T extends Serializable> extends WebPage
> {
> public CrudPage(PageParameters pps , AbstractDao<T> dao)
> {...}
> }
>
> and here is how I initialize the page :
> CrudPage<User> page = new CrudPage<User>(pps , userDao);
>
> the userDao is a Spring injected DAO :
> @SpringBean private UserDao userDao;
>
> And in fact , UserDao extends Abstract Dao Pattern :
> public interface UserDao extends AbstractDao<User> {...}
>
> Here comes the problem :
> I want to know which type is passed to CrudPage , I use the code :
>
> ParameterizedType genericSuperclass = (ParameterizedType)
> dao.getClass().getGenericSuperclass();
> this.clazz = (Class<T>) genericSuperclass.getActualTypeArguments()[0];
>
> But it throws exception :
> java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType
>
> I then print the type :
> System.out.println("dao.getClass() = " + dao.getClass());
> System.out.println("dao.getClass().getGenericSuperclass() = " +
> dao.getClass().getGenericSuperclass());
>
> and found the dao is proxied :
> dao.getClass() = class org.apache.wicket.proxy.$Proxy101
> dao.getClass().getGenericSuperclass() = class java.lang.reflect.Proxy
>
> Maybe that's why I cannot get the type ...
>
> And ... how to solve the problem ?
>
> Thanks a lot !
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org