On the other hand, if we make it accessible for classes in the same package,
we shall be able to test this method easily by putting test classes into this package.
There is also an alternative method to define an event handler method without using
an annotation. In this case we encode all the relevant information into the method
name. The name of an event handler should begin with an on, followed by the name
of the event, like this:
onSubmit() {}
Tapestry will automatically invoke this method for every Submit event that happens
on the page. Say, if you have more than one Form component on a page, this method
will run every time any of the forms is submitted.
If, however, you want to associate an event handler with a certain component, just
add the word From to the method name, followed by the component's ID (with first
letter capitalized). Here is the annotation-free equivalent of the event handler that
was created previously using the @OnEvent annotation:
void onSubmitFromUserInputForm()
{
System.out.println("Handling form submission!");
}
In fact, using such a naming convention for defining an event handler is the
preferred approach for the developers of Tapestry framework.
Pages:
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88