As you already know, this means that the event handler method should be invoked
in response to the submit event generated by the component with a specified ID.
The Form component generates a few other events too. There are three events related
to validation??”validate, success, and failure. Let's implement event handler
methods for all these events.
This is where following the naming convention for event handlers, as opposed to
using the @OnEvent annotation, will save us some effort. If Tapestry will find a method
named onSuccess() in the page class, it will understand that this is the event handler
for any success event that happens on the page. Let's modify the existing handler for
the submit event and add handlers for the other events mentioned above. Here is how
these methods should look in the Registration class:
String onSubmit()
{
System.out.println("The form was submitted!");
if (unsubscribe) subscribe = false;
return nextPage;
}
void onValidate()
{
System.out.println("In onValidate.");
}
void onSuccess()
{
System.out.println("In onSuccess.");
}
void onFailure()
{
System.out.println("In onFailure.");
}
User Input Validation
[ 168 ]
As usual, we have inserted some output statements to have a glimpse into the inner
life of Tapestry.
Pages:
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216