That being the case, is there any way to get an instance that I can cast to
a concrete type?


On Tue, Jul 23, 2013 at 9:27 AM, Martin Grigorov <mgrigo...@apache.org>wrote:

> Hi,
>
>
> On Tue, Jul 23, 2013 at 6:20 PM, Daniel Watrous <dwmaill...@gmail.com
> >wrote:
>
> > Hi,
> >
> > I'm having an issue that I suspect is related to the wicket integration
> > with Guice. Any help is appreciated.
> >
> > I have a Page class that uses field injection to inject a DAO. I then
> want
> > to cast my DAO to a more specific type (what I inject is the interface).
> > Here's what that looks like
> >
> > public class CnavModify extends ConsoleBasePage {
> >
> >     @Inject private CnavUrlDAO cnavUrlDAO;
> >     public CnavModify(PageParameters parameters) {
> >         super(parameters);
> >         if (parameters.get("cnavid").toString() != null) {
> >             cnavid = new ObjectId(parameters.get("cnavid").toString());
> >         }
> >         if (cnavid != null) {
> >             cnavUrlModel = new
> >
> >
> DetachableCnavUrlModel(((MorphiaCnavUrlDAO)cnavUrlDAO).getCnavById(cnavid));
> >         }
> >     }
> > }
> >
> > When I try to cast it I get the following error:
> >
> > Last cause: $Proxy23 cannot be cast to
> > com.hp.honeybadger.persistence.dao.morphia.MorphiaCnavUrlDAO
> >
> > I am able to use the CnavUrlDAO as a CnavUrlDAO, but its type is $Proxy23
> > and I am unable to cast it to a concrete type.
> >
> > Is this Guice or Wicket related? Any idea how to get around this?
> >
>
> It is an error in your assumption.
>
> Wicket injects a proxy that implements CnavUrlDAO but knows nothing about
> the specific implementation about this interface.
> Whenever the proxy is used it delegates the call to the bean/service
> returned by Guice's injector (something like:
> Injector.getBinding(CnavUrlDAO.class).doSomething()).
>
>
> >
> > Thanks,
> > Daniel
> >
>

Reply via email to