Java Reference
In-Depth Information
Deleting Contacts
To delete the contact when the user clicks the Delete link, we just need
a
delete
( ) event handler in
ContactListActionBean
:
public
Resolution delete() {
contactDao.delete(contactId);
return new
RedirectResolution(getClass());
}
After deleting the contact, we are using a
RedirectResolution
to the action
bean instead of a
ForwardResolution
to the JSP. I'll explain this in Sec-
3.5
Displaying Messages to the User
When the user clicks a Delete link, the contact is immediately deleted.
This could be a little more forgiving. Since deleting a contact is such a
drastic operation, we want the user to confirm before proceeding—just
in case the user had a twitch and clicked the link by mistake.
“Are You Sure?” Messages
To ask for confirmation before proceeding, we can use the
onclick=
attribute in the link. This and other standard HTML attributes are
accepted by Stripes tags as “pass-through,” meaning that the attribute
and its value are rendered as is. Clicking the link executes the Java-
Script code provided in
onclick=
:
<s:link beanclass="stripesbook.action.ContactListActionBean"
event="delete"
onclick="return confirm('Delete ${contact}?');">
<s:param name="contactId" value="${contact.id}"/>
Delete
</s:link>
This asks the user to confirm the operation using the dialog box shown
the name of the contact in the message that appears in the dialog box.
This is nicer than a catchall message such as “Delete the selected con-
tact?” because we also confirm which contact to delete.
Search WWH ::
Custom Search