Java Reference
In-Depth Information
Figure 3.13: Prepopulated form
Remember that the
getContact
( ) method in
ContactBaseActionBean
al-
ready retrieves the selected contact if the contact ID parameter was
provided:
public
Contact getContact() {
if
(contactId !=
null
) {
return
contactDao.read(contactId);
}
return
contact;
}
The nice thing with the Stripes input tags is that they also read from
the property in the
name=
attribute. So by making the selected contact
available through
getContact
( ), the inputs prepopulate themselves with
the contact information such as "contact.firstName", "contact.lastName",
and so on.
Just like that, we're almost there. To get the form to work for updating
an existing contact, we need to resubmit the contact ID parameter that
was sent with the Update link.
A hidden input does the trick:
<s:form beanclass="stripesbook.action.ContactFormActionBean">
<div><s:hidden name="contact.id"/></div>
<table class="form">
The input obtains its value just like the other inputs and becomes a
parameter when the form is submitted. It took very little code to add the
Search WWH ::
Custom Search