In the first case, the specified
component will be marked as an error. Let's say that if passwords do not match,
we want to mark the password component as an error. For this, we need to have a
reference to this component in the page code:
@Component(id="password")
private PasswordField passwordField;
Here we couldn't give the reference the same name as the ID of the component, since
there is already a class member named password. So we used a different name for
the reference (passwordField) and specified exactly which component we meant in
the id parameter passed to the @Component annotation.
Also, we'll want to provide an error message to be automatically displayed by the
Errors component. The proper place for such a message is the application's (or
page's) message catalog, so let's add some error message to the app.properties file:
passwords-dont-match=Two versions of password do not match.
And then we need to provide a reference to this catalog in the page class:
@Inject
private Messages messages;
Finally, we can write the contents for the onValidate method:
void onValidate()
{
System.out.println("In onValidate.");
if (!password.equals(password2))
{
password = null;
registrationForm.
Pages:
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220