Apache Wicket Cookbook

Packt recently published Igor Vaynberg's "Apache Wicket Cookbook" and I was fortunate enough to receive a review copy.  I've been a Wicket user since long before it was Apache Wicket.  I've developed applications ranging in complexity from simple IRC bot log viewers to conference management suites.  Knowing Wicket reasonably well, I tend to not bother reading books on the subject as most of them are aimed at the beginner.  And those I find just a tad boring. What caught my eye about this book in particular, though, was the "cookbook" approach to the writing.  This book does assume that you know at least the basics of Wicket.  It doesn't spend any time on trying to justify Wicket's design or approach.  What it does do is get you into your code quickly.  The examples cover clearly a number of very common use cases and starts to fill in the corners (to borrow a phrase from Tolkien).  What I appreciated most about this book is that there are so many things that we, as wicket users and developers, just do because that's How It's Done.  While he doesn't start you from zero, Igor takes some time to explain a few of the whys and wherefores:  the sometimes subtle implications of why things are done certain ways, the consequences and options of other approaches.

The tone of the book is light and easy.  Unlike a "from scratch" style book, this one really is just a reference book of sorts.  If you'd like to deepen your understanding of Wicket, you should certainly read this cover to cover.  However, if you're just struggling with a topic or two, the targeted approach of the writing lets you zoom in on your problem and get back out to your app with little fuss.  It's the kind of book that I think long time users will appreciate.  If you use wicket to any extent, it wouldn't hurt to have a copy of this handy.

To whet your appetite, Packt Publishing has made a chapter available.  Chapter 5, Displaying Data Using Data Table, can be freely downloaded directly from the publisher's site.  Looking at the table of contents, you can see the book covers quite few hot spots in the development of any application:

  • Chapter 1: Validating and Converting User Input
    • Introduction
    • Performing form-level custom validation
    • Creating a custom validator
    • Composing multiple validators into a single reusable validator
    • Converting string inputs to objects
  • Chapter 2: Getting Down and Dirty with Forms and Form Components
    • Introduction
    • Creating linked selectboxes
    • Composing multiple form components into a single reusable component
    • Preventing multiple form submits
    • Protecting against spam with a CAPTCHA
  • Chapter 3: Making Forms Presentable
    • Introduction
    • Changing form component CSS class on validation errors
    • Using FeedbackPanel to output form component specific messages
    • Streamlining form component presentation using behaviors
  • Chapter 4: Taking your Application Abroad
    • Introduction
    • Storing module resource strings in package properties
    • Retrieving a localized string
    • Feeding dynamic localized strings to components using StringResourceModel
    • Using wicket:message to output localized markup
    • Overriding localized resources on a case by case basis
  • Chapter 5: Displaying Data Using DataTable
    • Introduction
    • Sorting
    • Filtering
    • Making cells clickable
    • Making rows selectable with checkboxes
    • Exporting data to CSV
  • Chapter 6: Enhancing your UI with Tabs and Borders
    • Introduction
    • Creating tabs with dynamic titles
    • Making a tabbed panel play nice with forms
    • Creating a client-side JavaScript tabbed panel
    • Using borders to decorate components
    • Creating a collapsible border
  • Chapter 7: Deeper into Ajax
    • Introduction
    • Adding Ajax validation to individual form components
    • Blocking until an Ajax request is complete
    • Providing Ajax feedback automatically
  • Chapter 8: Visualizing Data with Charts
    • Introduction
    • Charting with Open Flash Chart
    • Feeding chart data using a SharedResource
    • Responding to clicks
  • Chapter 9: Building Dynamic and Rich UI
    • Introduction
    • Swapping components using a select box
    • Creating dynamic forms
    • Creating a dynamic portal layout
  • Chapter 10: Securing your Application
    • Introduction
    • Creating a login page and forcing the user to log in
    • Authenticating with OpenID
    • Securing components using
    • IAuthorizationStrategy
    • Securing URLs and protecting against cross-site request forgery
    • Switching from HTTP to HTTPS and back again
  • Chapter 11: Integrating Wicket with Middleware
    • Introduction
    • Integrating with Spring
    • Integrating with CDI
    • Populating repeaters from a JPA query
    • Creating a model for a JPA entity

All told this is a great book and a great addition to your library.  This is easily something I'll keep coming back to while building wicket apps.

 

Wicket and Embedded GlassFish

One of the newer features available in GlassFish v3 is the ability to run glassfish in an embedded mode similar to how jetty is often used. This is approach is very common when working with Wicket and is, in fact, part of the quickstart maven archetype.  So what I'd like to see is GlassFish in place of Jetty.  It's not terribly difficult once you get past the first few steps.  This is a pretty new (and evolving) option so the documentation isn't all that easy to find, necessarily, but it's building.  I'll list some resources at the end. The first step, of course, is to configure maven appropriately.  In my pom.xml, I have the following:

    
        
            glassfish-repository
            GlassFish Nexus Repository
            http://maven.glassfish.org/content/groups/glassfish
        
    

This will add the repository to find the deployed GlassFish artifacts. With that done, we can define a few dependencies:

        
            org.glassfish.common
            glassfish-api
            ${glassfish.version}
            provided
        
        
            org.glassfish.extras
            glassfish-embedded-web
            ${glassfish.version}
            provided
        
        
            org.glassfish.web
            web-embed-impl
            ${glassfish.version}
            provided
        

${glassfish.version} here is defined elsewhere in the pom to 3.0. The class at the center of it all looks like this:

public class Embedded {
    public void start() throws IOException {
        final Server server = new Server.Builder("testBuilder").build();
        ContainerBuilder containerBuilder = server.createConfig(ContainerBuilder.Type.web);
        server.addContainer(containerBuilder);
        final EmbeddedWebContainer container = (EmbeddedWebContainer) containerBuilder.create(server);
        container.setLogLevel(Level.INFO);
        server.createPort(8888);
        final EmbeddedDeployer deployer = server.getDeployer();
        DeployCommandParameters deployParams = new DeployCommandParameters();
        deployParams.contextroot = "/";     // overrides whatever the WAR contains
        File archive = new File("target/wicket-glassfish").getAbsoluteFile();
        System.out.println("Deployed: " + deployer.deploy(archive, deployParams));
    }

    public static void main(String[] args) throws Exception {
        new Embedded().start();
        while (true) {
            Thread.sleep(1000);
        }
    }
}

Now, that's all rather dense, I know. This code is a condensed version of a much larger, more complete version written by Alexis Moussine-Pouchkine. His blog is a great resource not only for embedded GlassFish but all sorts of GlassFish related topics. This is all that's needed to run your app on GlassFish.

There are a number of other avenues left to explore. If you want to run glassfish from maven, you'll want to probably look at this entry. You can also enable some security as noted here. For the definitive word on the matter, however, please see the formal documentation for embedded glassfish here.

Groovy on the web the right way?

I've recently started (re)exploring the world of Groovy and, thus, Grails. The idea of Groovy makes me pretty happy, but Grails kinda makes me cry for a number of reasons. The entire system is, as you probably know, basically RoR but with Groovy complete with scaffolding. The issues with scaffolding are well documented. Most of the scaffolding gets thrown away once you start doing anything "real" and Grails can certainly suffer from that. You can, of course, write your own templates and these templates are basically JSPs implemented with a Groovy flavor. This is where my disappointment really starts to build. JSPs, at least in my circles, are all but deprecated. Even JSF2 is moving away from a JSP-centric view and moving on to JSFTemplating. So why did the Grails guys decide to reimplement JSP? But there's light at the end of the tunnel for me. There are two different projects that give me hope for using Groovy on the web tier: Gracelets and the Wicket Grails Plug-in. Both of these projects have two things going for them:

  1. They leverage existing frameworks and their component sets so we're not left reimplementing everything else as well.
  2. They use more component oriented approaches than JSP development tends to lead to.

I like the dynamic nature of Groovy and the fact you don't need to restart jetty every time you change a class. Maybe these options will make Groovy more palatable on the web. For me at least.