Java Reference
In-Depth Information
public
Resolution save() {
Contact contact = getContact();
getContactDao().save(contact);
getContext().getMessages().add(
new
SimpleMessage("{0} has been saved.", contact)
);
return new
RedirectResolution(ContactListActionBean.
class
);
}
public
Resolution cancel() {
getContext().getMessages().add(
new
SimpleMessage("Action cancelled.")
);
return new
RedirectResolution(ContactListActionBean.
class
);
}
}
We'll now add some validations to this form.
Making a Field Required
Let's begin by making the contact's email address a required field. First,
it's better to let the user know up front about required fields. One way is
to make the field border thicker by adding a "required" class and styling
it in the CSS file:
<s:text name="contact.email" class="required"/>
input.required {
border-width: 2px;
}
Next, adding
@ValidateNestedProperties
with
@Validate(field="email")
to
con-
tact
validates the "contact.email" nested property. Remember that the
contact
property moved to the parent
ContactBaseActionBean
, so the val-
idation must override either the getter or the setter method in
Contact-
FormActionBean
:
@ValidateNestedProperties({
@Validate(field="email", required=
true
, on="save")
})
@Override
public void
setContact(Contact contact) {
super
.setContact(contact);
}
Search WWH ::
Custom Search