A downloadable zip file is available for this article. The simplest approach We have already used one listener method in our GuessTheWord application. Let’s remind ourselves how we did that. In the Home.html template we created a form: <form action="" jwcid="secretWordForm"> … some content … </form> Then in the Home.page specification we told Tapestry what to do when the form is submitted: <component id="secretWordForm" type="Form"> <binding name="listener" value="listener:onWordSubmit"/> </component> Which basically means that we want the onWordSubmit() listener method of the Home class to be invoked. And here is the method itself: public String onWordSubmit() { return "Secret"; } Right now, the listener method is very simple. It does not perform any processing and simply returns a String. Tapestry understands this as “Show the page with this name, please!” and displays the Secret page. But the listener method could be even simpler than this, for example: public void onWordSubmit() { // Do something } This version returns nothing – so the same page will be redisplayed. But if we put some code inside of the method, it will be executed, of course. More often however we want some other page to be shown, and not only that, but we want to somehow prepare the next page before showing it.
blog comments powered by Disqus |
|
|
|
|
|
|
|