Tuesday, October 26, 2010

Tapestry 5.1 @OnEvent not firing

Submit buttons in Tapestry 5.1 not firing their @OnEvent handlers


There are a lot of examples out there in the ether for a tapestry 5 submit button handler. And they don't work right off the bat.

Bad Example

If you read Tapestry 5: Building Web Applications you will find an example of a form submit button handler.

blah.tml:
   <input type="submit" t:type="submit" t:id="submitButton" value="Submit"/>

blah.java:
    @OnEvent(component="submitButton")
    void onSubmitButton()
    {
      System.out.println("Submit button was pressed!");
    }


It doesn't work. Then you start stepping through the code and learning more than anyone wants to know about tapestry's event handling. Note: i did not step through the code or learn anything about tapestry's event handling.


The problem is that the default for @OnEvent 's value parameter is 'action'.
The default event value for a submit button is 'selected'.

Good Example



blah.tml:
   <input type="submit" t:type="submit" t:id="submitButton" value="Submit"/>

blah.java:
    @OnEvent(component="submitButton", value="selected")
    void onSubmitButton()
    {
      System.out.println("Submit button was pressed!");
    }

Read the book

I really did like the book Tapestry 5: Building Web Applications. It has a lot of simple recipes. Well presented concepts.

Also the beginners Guide Tutorial on the tapestry home page is very good. Gets you up and running with a default application very quickly. Assuming you can hack your way by the typos and deprecated maven commands.

They both suffer from the fact that tapestry changes in little ways and the documentation gets stale pretty quickly. Hey, just like code in the real world.

No comments:

Post a Comment