out.println("Submit button was pressed!");
User newUser = new User("John", "Johnson");
this.user = newUser;
nextPage = ShowAll.class;
}
We have modified the form submission handler. It now returns a String, and
the value to return is taken from the newly added nextPage class variable. We
are submitting the form each time a check box is clicked, and each time the form
submission handler runs??”but that is fine. The value of the nextPage variable is null
(until we specifically assign something to it), so the form submission handler returns
null, and Tapestry redisplays the same page; that is, everything works as before.
But when the Submit button is clicked on, its event handler assigns the class of the
ShowAll page to the nextPage variable. The form submission handler that runs
immediately afterwards picks up this value and returns it, and the ShowAll page is
shown by Tapestry as a result.
As you can see, the use of the Submit component gives us significant flexibility
while handling form submission??”we can have more than one method running
in response.
In fact, we can also have more than one Submit component in the form.
More Than One Submit Button
Many Web applications give their users an opportunity to quickly "erase" the
information they have just entered in case they change their mind.
Pages:
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163