CRUD With Wicket + Guice + Db4o / NeoDatis
Join the DZone community and get the full member experience.Join For Free
the journey began with a search for a database for my desktop application timefinder . it turned out that there are at least 3 candidates if i would choose a simple and only one tier architecture:
one tier applications would only make sense for some special uses cases like in my case for high schools with one timetable admin. but it would be a lot better if i could use sth. like remote gorm , remote object persistence or even an ajaxified web application. yes. why not? what, if i rewrite the ui from scratch and move from ‘swing desktop’ to web? but then again: which web framework and which persistent architecture?
a lot of people would recommend grails (myself included) if i need a simple crud web framework, but for me grails is a bit heavy weight (~ 20 mb) and i will have to live with at least 6 languages: gsp, js, html, ‘spring-xml’, java and groovy. i will need java at least for the performance critical part: the timetabling algorithm.
from what i learned in the last days and from blog posts; wicket is outstanding in the following areas:
separation of ui and code. you only have
- and pure java . this is very good if you’ll someday refactor your code. and you’ll.
- you can create your own components easy and fast. you can even create ajax components without xml and js… only java.
- a strong community (even a german book )
okay. and the persistent layer? that was the reason for this journey … hmmh, there are already several different persistent ‘technics’ for wicket available:
hmmh, but i only need a very simple persistent layer. no complex queries etc. as i mentioned earlier i can even live with xml (for datastorage). i decided to look into db4o again (used it in gstpl which is the antecessor of timefinder) and into the more commercial friendly (lgpl) object oriented database neodatis . the latter one has an option to export to xml and import the same, this would be great so that i don’t have to think about database migrations (some refactorings will be applied automatically. see 1.10 in the pdf docs ). migration in db4o should be easy too.
while i was thinking about that, i asked on the apache wicket mailing list for such simple persistent solution. jeremy thomerson pointed out that there are even some maven archetypes at jweekend which generates a simple wicket app with persistence for me. i chose the wicket+guice+jpa template and updated this to use guice 2.0 and the latest warp-persist according to this post . after that i needed to make db4o or neodatis working. for the latter one i needed warp-persist-neodatis and for the first one i only needed some minor changes, but they took a bit longer.
for those who want to see the results, here are the 2 independent maven projects (apache license 2.0) within my subversion repository (revision 781):
wicket with guice and db4o
wicket with guice and neodatis (not all features are implemented as of jan 2010)
and here is a screenshot:
as you can see the localized warning messages are already provided and shown instead of “please enter a value into the field ‘location’”. to try the examples just type ‘mvn install’ and run ‘mvn jetty:run’. then point your firefox or opera to
to work with wicket is a great experience! in another project it took me about 10 minutes to convert a normal submit into an ajax one which updates only selected components. and then, in the neodatis project i initiallly developed my eventdataview against a completely different data item and moved the source nearly unchanged to the db4o project with the event class! that is nice component oriented development. okay, i did copy and paste rather then creating a maven submodule for the pageable list, but that wouldn’t be that difficult with wicket. then as a third example i overwrote the navigation panel, which was easy too: now instead of
<< < 1 2 ... > >>
it will be shown
first prev 1 2 ... next last.
without touching the ui. you can even provide ‘properties’ files to apply easy i18n.
wicket is like coming home ‘to desktop’ after some years of web development, especially in the ui layer. and guice perfectly meets my dependency injection requirements: pure java.
to get all things right i had to tweek the initial example of jweekend a lot, but all necessary changes were logically and does not smell like a hack. as a first step i updated the versions of the artifacts and then i added a dataview from the repeater examples . the developed crud example is now built with dependency injection instead of the original locator pattern (ala databaselocator.getdb()):
then the update mechanism and some other exception must be solved, but you only need to check out the sources and see what is possible!
as a side note
please keep in mind that there is a netbeans plugin for wicket 1.4.x and an intellij plugin for the same. for all netbeans guys which are interested in ‘deploy on save’ feature you only need to enable ‘compile on save’ and then you can change code or html in wicket, if you are running the application via jetty:run (jetty configuration is already done in the pom). currently this works only with db4o as a standalone server. to my knowledge this way of ui prototyping can be even faster than with grails, where it could take some seconds to be recompiled.
dive into the world of wicket right now!
Opinions expressed by DZone contributors are their own.