CRUD With Wicket + Guice + Db4o / NeoDatis
Join the DZone community and get the full member experience.
Join For Freethe 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.
okay. then, why not gwt or eclipse rap ? gwt has javascript compilation, which i am not a big fan of and eclipse rap requires pure eclipse development, i guess. so what else? there are a lot of java web frameworks ( with ajax ) as i discovered earlier . my choice now was simple: wicket , which is swing for the web. but what if you don’t like swing? then you will love the ‘swing for the web’ !
wicket features
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
- pure html no new syntax required ala jsp, jsf, gsp, velocity, … the latter one was the reason for not choosing click. no javascript hassle … if there are some, then i trust the wicket community to fix them in wicket itself
- 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:
- wicketopia
- databinder
- wicketrad
- wicket-iolite
- wicket-phonebook
- … and pure hibernate
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.
resources
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
https://timefinder.svn.sourceforge.net/svnroot/timefinder/branches/timefinderwicket -
wicket with guice and neodatis (not all features are implemented as of jan 2010)
https://timefinder.svn.sourceforge.net/svnroot/timefinder/branches/timefinderwicketneodatis
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
http://localhost:8080/timefinderwicket/
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.
coming home
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()):
@inject
provider<objectcontainer> oc;
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.
conclusion
dive into the world of wicket right now!
Opinions expressed by DZone contributors are their own.
Comments