How does wicket know which module to inject?

_______________________________________
Stephen Walsh | http://connectwithawalsh.com


On Sun, Mar 17, 2013 at 12:59 PM, Dan Retzlaff <dretzl...@gmail.com> wrote:

> Wicket only injects Components and Behaviors by default. To inject into
> anything else, call Injector.get().inject(this) in its constructor.
>
> On Fri, Mar 15, 2013 at 2:27 PM, Stephen Walsh <
> step...@connectwithawalsh.com> wrote:
>
> > I have a much better understanding on this now.  Are there any plans to
> > support injection on LDMs, or is there a suggested work around for this?
> >
> > It seems like you'd want a DAO service to get an object from the DB
> within
> > a custom model so you can return that back to your component.
> >
> > _______________________________________
> > Stephen Walsh | http://connectwithawalsh.com
> >
> >
> > On Thu, Mar 14, 2013 at 5:03 PM, Martin Grigorov <mgrigo...@apache.org
> > >wrote:
> >
> > > Take a look at wicket-examples and the unit tests in wicket-guice
> module.
> > >
> > >
> > > On Thu, Mar 14, 2013 at 10:53 PM, Stephen Walsh <
> > > step...@connectwithawalsh.com> wrote:
> > >
> > > > Any other thoughts on this?
> > > >
> > > > _______________________________________
> > > > Stephen Walsh | http://connectwithawalsh.com
> > > >
> > > >
> > > > On Thu, Mar 14, 2013 at 10:30 AM, Stephen Walsh <
> > > > step...@connectwithawalsh.com> wrote:
> > > >
> > > > > Thanks, Martin.  I intialize here, (which I just realized is not
> the
> > > best
> > > > > spot):
> > > > >
> > > > >     private void setUpMongo() {
> > > > >         mongo = MongoUtil.getMongo();
> > > > >         morphia = new Morphia().map(Blog.class).map(Person.class);
> > > > >         blogDAO = new BlogDAO(mongo, morphia);
> > > > >     }
> > > > >
> > > > > I am using the Wicket Guice module, and I think your second point
> is
> > > what
> > > > > I was getting at.  From learning about Guice (
> > > > > http://www.youtube.com/watch?feature=player_embedded&v=hBVJbzAagfs
> ),
> > I
> > > > > thought the point was to initialize once and then reuse wherever
> > > needed.
> > > >  I
> > > > > figured initialization would happen in the application class.
>  Maybe
> > > I'm
> > > > > misunderstanding.  If it's supposed to happen in the application
> > class,
> > > > > then I don't really have need for a module because I don't have an
> > > > > interface in this case, right?
> > > > >
> > > > > Thanks for the help on this.
> > > > >
> > > > > _______________________________________
> > > > > Stephen Walsh | http://connectwithawalsh.com
> > > > >
> > > > >
> > > > > On Thu, Mar 14, 2013 at 3:20 AM, Martin Grigorov <
> > mgrigo...@apache.org
> > > > >wrote:
> > > > >
> > > > >> Hi,
> > > > >>
> > > > >> I don't see how you initialize blogDAO. If you don't use
> wicket-ioc
> > > > module
> > > > >> then you will need to lookup the DAO from the application whenever
> > you
> > > > >> need
> > > > >> it:
> > > > >>
> > > > >> public void onSubmit() {
> > > > >>
> > > > >>   BlogDAO blogDao = MyApplication.get().getBlogDAO();
> > > > >>   blogDao.save(blog);
> > > > >> }
> > > > >> This way you wont keep reference to it in the page/component and
> it
> > > wont
> > > > >> be
> > > > >> serialized.
> > > > >>
> > > > >> If you use wicket-guice module then you can do:
> > > > >>
> > > > >> @Inject
> > > > >> private  BlogDAO blogDao;
> > > > >>
> > > > >> and use it anywhere.
> > > > >> Wicket will use Guice to lookup the bean at component creation but
> > the
> > > > >> bean
> > > > >> will be wrapped in a serializable proxy. That is a lightweight
> proxy
> > > > will
> > > > >> be (de)serialized with the page.
> > > > >> This is the recommended way.
> > > > >> wicket-string works the same way.
> > > > >> wicket-cdi leaves the proxy creation to the CDI implementation.
> > > > >>
> > > > >>
> > > > >>
> > > > >> On Thu, Mar 14, 2013 at 5:19 AM, Stephen Walsh <
> > > > >> step...@connectwithawalsh.com> wrote:
> > > > >>
> > > > >> > I'm attempting to implement Guice for my DAO connections as my
> > JBoss
> > > > >> server
> > > > >> > keeps running out of memory.  Not entirely sure why that is, but
> > I'm
> > > > >> hoping
> > > > >> > this is at least part of it.  I read through
> > > > >> > http://markmail.org/message/sz64l4eytzc3ctkh and understand why
> > the
> > > > DAO
> > > > >> > needs to be serialized, and I also followed
> > > > >> >
> > > > >> >
> > > > >>
> > > >
> > >
> >
> https://cwiki.apache.org/confluence/display/WICKET/Wicket%2C+Guice+and+Ibatis+exampleto
> > > > >> > try and figure out where and how exactly to inject my DAO.
> > > > >> >
> > > > >> > My DAO already extends a basic DAO class that has all of the
> > basics
> > > > for
> > > > >> > getting stuff from the database.  Neither of these are
> interfaces
> > > (not
> > > > >> sure
> > > > >> > if this is a problem or not).  My DAO works just fine in panels,
> > but
> > > > as
> > > > >> > soon as it's on a page, it throws the not seralizable exception.
> > > > >> >  Regardless it doesn't really solve the problem of really only
> > > needing
> > > > >> one
> > > > >> > DAO for the whole application instead of creating one whenever
> > it's
> > > > >> needed
> > > > >> > in every place that it's needed.  If I understand dependency
> > > > injection,
> > > > >> > then this is the whole point.
> > > > >> >
> > > > >> > Here's my class.  Hopefully someone can point me in the right
> > > > direction
> > > > >> for
> > > > >> > this page and my application class:
> > > > >> >
> > > > >> > public class EditBlogEntry extends BasePage {
> > > > >> >
> > > > >> >     private Logger logger =
> > > > >> LoggerFactory.getLogger(EditBlogEntry.class);
> > > > >> >
> > > > >> >     private Mongo mongo;
> > > > >> >     private Morphia morphia;
> > > > >> >     private BlogDAO blogDAO;
> > > > >> >
> > > > >> >     public EditBlogEntry(final Blog blogEntry) {
> > > > >> >  // Add edit blogPost form to page
> > > > >> >         Form<?> form = new Form("form");
> > > > >> >         form.add(new Button("postIt") {
> > > > >> >             @Override
> > > > >> >             public void onSubmit() {
> > > > >> >                 // This merely gets a new mongo instance that
> has
> > my
> > > > >> blog
> > > > >> > entry mapped by morphia for saving the whole POJO to mongo
> > > > >> >                 setUpMongo();
> > > > >> >                 blogDAO.save(blogEntry);
> > > > >> >                 BlogEntryDetails details = new
> > BlogEntryDetails(new
> > > > >> > PageParameters().add("id", blogEntry.getObjectId().toString()));
> > > > >> >                 setResponsePage(details);
> > > > >> >             }
> > > > >> >         });
> > > > >> >
> > > > >> >         LoadableDetachableModel ldm = new
> > LoadableDetachableModel()
> > > {
> > > > >> >             @Override
> > > > >> >             protected Object load() {
> > > > >> > //                TODO need to set athr only on new blogEntry
> > > > >> >
> > > > blogEntry.setAthr(CampingAwaitsSession.get().getUser());
> > > > >> >                 return blogEntry;
> > > > >> >             }
> > > > >> >         };
> > > > >> >
> > > > >> >         form.add(new BlogEntryPanel("blogEntry", new
> > > > >> > CompoundPropertyModel<Blog>(ldm)));
> > > > >> >         add(form);
> > > > >> >
> > > > >> > }
> > > > >> >
> > > > >> > Any thoughts?  I feel like I understand the concept but the
> > > > >> implementation
> > > > >> > is throwing me.
> > > > >> >
> > > > >> > _______________________________________
> > > > >> > Stephen Walsh | http://connectwithawalsh.com
> > > > >> >
> > > > >>
> > > > >>
> > > > >>
> > > > >> --
> > > > >> Martin Grigorov
> > > > >> jWeekend
> > > > >> Training, Consulting, Development
> > > > >> http://jWeekend.com <http://jweekend.com/>
> > > > >>
> > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > Martin Grigorov
> > > jWeekend
> > > Training, Consulting, Development
> > > http://jWeekend.com <http://jweekend.com/>
> > >
> >
>

Reply via email to