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