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 <small...@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-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to