Java Reference
In-Depth Information
<tr>
<td> Last name: </td>
<td><s:text name="contact.lastName"/></td>
</tr>
<tr>
<td> Phone number: </td>
<td><s:text name="contact.phoneNumber"/></td>
</tr>
<tr>
<td> Birth date: </td>
<td><s:text name="contact.birthDate"/></td>
</tr>
<tr>
<td> &nbsp; </td>
<td>
Ì
<s:submit name="save" value="Save"/>
<s:submit name="cancel" value="Cancel"/>
</td>
</tr>
</table>
</s:form>
At Ê , we're creating a form associated with the ContactFormActionBean
class, which we'll be writing shortly. Starting at Ë , the text input fields
for the contact's information are created with the <s:text> tag and
name= attributes for the properties of the Contact class. The submit
buttons ( Ì ) call either save ( ) or cancel ( ) on the action bean according
to which one the user clicked. The value= attribute is the button's label.
Notice how there is a very clean and clear relationship between the
JSP and the action bean. The action bean's class name is indicated in
the form tag's beanclass= attribute, each input's name= corresponds to
an action bean property, and each submit button's name= is an action
bean's event handler.
Let's create the ContactFormActionBean to handle the form submission.
We'll need the following:
• A default event handler that forwards to contact_form.jsp
• The save ( ) and cancel ( ) event handlers
• The contactId and contact properties
• The ContactDao to save the contact
Looking at those last two points, you'll realize that the ContactListAction-
Bean class already has the contact properties and DAO. You probably
don't like copying and pasting code any more than I do, so let's do a
little refactoring.
 
Search WWH ::




Custom Search