Java Reference
In-Depth Information
public Contact getContact() {
if (contactId != null ) {
return contactDao.read(contactId);
}
return contact;
}
public void setContact(Contact contact) {
this .contact = contact;
}
}
The code in the ContactFormActionBean class is now lean and mean:
Download email_05/src/stripesbook/action/ContactFormActionBean.java
package stripesbook.action;
public class ContactFormActionBean extends ContactBaseActionBean {
private static final String FORM="/WEB-INF/jsp/contact_form.jsp";
@DefaultHandler
Ê
public Resolution form() {
return new ForwardResolution(FORM);
}
Ë
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 );
}
}
The default event handler at Ê forwards to contact_form.jsp . When the
user clicks the Save button, save ( ) is called ( Ë ) and uses the DAO to
save the contact. It then adds an information message to the list and
redirects to ContactListActionBean , which displays the messages and the
table of contacts. The event handler for the Cancel button ( Ì ) just adds
an information message and redirects to the contact list without saving
the contact.
 
Search WWH ::




Custom Search