16 thoughts on “Generic Bean Editing with Apache Wicket – Presentation & Code

  1. somatik

    How do you cope with toEdit.getClass().getDeclaredFields() returing the fields in a undefined order? What if I want to have my form fields ordered?

    form the javadoc: “The elements in the array returned are not sorted and are not in any particular order”

    Would you define some static final array containing fieldnames? That would kill refactoring support.
    Would you add some ordering annotation? In the end all those annotation just make your class less readable?

    Reply
  2. Alastair Post author

    Sure, you could add an ordering annotation if you like. You could argue that this is a view layer thing, so you shouldn’t clutter the bean with stuff like that. Your call.

    I hadn’t thought about ordering, to be honest, as I find that the Sun JDK tends to return things in order, whether the javadoc says it does or not. ;-)

    If you’re localising your field name labels then you’ve killed refactoring support anyway.

    You say “all those annotations”, but really, there aren’t many, or if there are any, then they’ll be JPA or Hibernate annotation ones, so using this approach isn’t really adding anything extra.

    I’m not saying you can just take this code and run with it for your project. I’m giving it to you as a starting point, and to get you thinking about more abstract ways of building your web apps.

    Reply
  3. Jonathan Locke

    beautiful! i’ve been talking about doing this for a couple years now, but you actually went and did it. ;-)

    i think we ought to make it a goal for wicket 1.4 to pull together a suite we could call something like “wicket on wings” (to compete with ruby on rails). this would simply assemble a bean editor framework like this with something like the constraint annotations and feedback bubbles behaviors we’ve been developing at my workplace to make this stuff slicker and more ajaxy and as turnkey as ruby, only typesafe, refactorable, discoverable, secure, etc.

    you ought to be able to do new ObjectEditor(model) and get an excellent default which is also highly customizable.

    my personal belief is that there is a need to have both a repeater version of this that’s fully automatic but also a version which allows full manual html layout of the editor panel. that could be a different class, a subclass or just a flag, but it ought to exist.

    Reply
  4. Jonathan Locke

    for the manual layout mode, i think there ought to be a way to output the markup that would be generated by the repeater as a starting point. that way i can just insert add(new ObjectEditorForm(model)) into my code, run some little tool to create the markup and hand it off to the designer to finish it.

    Reply
  5. Alastair Post author

    Yep. I’ve been thinking about that too. I have a generic listing component, but it’s too tightly coupled to the project it’s in at the moment.

    I’m almost tempted to mandate a particular way of DAO access working (like Rails does with ActiveRecord) and write some components around that, so we really do have something Rails-like, only type-safe, faster and more flexible.

    Reply
  6. JW

    You should dump that BeanEditor.mov into Youtube and get it embedded in your blog page so that people can get instant gratification.

    Reply
  7. Pingback: links for 2007-08-27 « Object neo = neo Object

  8. Michael Sparer

    That reminds of Tapestry’s BeanEditForm – ok it has less functionality yet, but I really like it. I played around a bit and added the order annotation discussed above within minutes (as a wicket-newbie) :-) Now I’m thinking about adding a generic validation of the fields. E.g. @Validate(minValue=5) … I think your introduction infected me with the wicket-virus ;-)

    Reply
  9. Alastair Post author

    I would embed it into YouTube, but there seem to be some issues encoding the thing – they don’t like initially static frames or something. I’ll set up the next one so it works properly there.

    Reply
  10. Ken

    nice, we have been looking into wicket for such functionality to replace our current infra. One more thing you might want to look at is the actions like onSubmit, onClick to push your bean to a generic web service interface perhaps

    Reply
  11. Pingback: Some wicket impressions | Molindo Techblog

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>