Databinder: chipping away at un-usabilityDatabinder: chipping away at un-usability

It’s time for a new Databinder snapshot, this one improving ease-of-use and tying into the latest from Hibernate.

It has annoyed me for some time that there’s no built-in click path from a Web app’s root to its Wicket servlet. I thought there would be some standard way to do redirects in a web.xml. Apparently not. I noticed some people putting an index.html in the Web root with a meta redirect to the servlet. Er…

So I got off my butt and wrote the simplest servlet in history; it just redirects to the URL specified in a paramater. I’ll enable it in the next data-app archetype release, but you can start using it in your web.xml already:

<servlet>
    <servlet-name>RedirectServlet</servlet-name>
    <servlet-class>net.databinder.util.RedirectServlet</servlet-class>
    <init-param>
            <param-name>redirectUrl</param-name>
            <param-value>app</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
        <servlet-name>RedirectServlet</servlet-name>
        <url-pattern>/</url-pattern>
</servlet-mapping>

No more typing ”/app” into your browser. Never again!

Update: We use a redirect filter now, since the servlet trapped requests to static (WEB-INF) resources. See example web.xml.

Along those same lines, meet net.databinder.components.Wrapper. It’s nothing but an extension of Wicket’s WebMarkupContainer that outputs a markup ID by default, but it will save you some keystrokes when coding Ajax functionality. (For one thing, “Wrapper” has 11 fewer characters than “WebMarkupContainer.” Cowabunga!)

Over in the forum, mindhaq and I determined that it’s better to load objects upon instantiation of a HibernateObjectModel instead of waiting until the model object is first requested. That way you can catch an ObjectNotFoundException, for example, without any secret moves.

Finally, I noticed that a new version of Hibernate Annotations is out. Wait—was out. They released beta 10 immediately after I had negotiated beta 9’s upload to the Maven repository, natch.

The new Databinder snapshot depends on Hibernate 2.3.0.cr1 and Hibernate Annotations 3.1.0 beta 9, both of which Maven will download automatically, and Wicket 1.2 RC2, which you will have to download and mvn install yourself.

Enjoy, and, if you feel like uploading Annotations beta 10 to the Maven repo, I sure won’t get in your way.

Add a comment