Java Reference
In-Depth Information
For example, with the Delete button associated to the delete ( ) event
handler, here's how we would delete the selected messages:
Download email_19/src/stripesbook/action/MessageListActionBean.java
public Resolution delete() {
for (Message message : selectedMessages) {
folderDao.deleteMessage(message);
}
return new RedirectResolution(getClass());
}
private FolderDao folderDao = MockFolderDao.getInstance();
Making sure that at least one message is selected is easy too. When
no checkbox is checked, the corresponding property on the action bean
will be null . So, all we have to do is make selectedMessages a required
field:
Download email_19/src/stripesbook/action/MessageListActionBean.java
@Validate(required= true , on={"delete", "moveToFolder"})
private List<Message> selectedMessages;
Let's not forget to display the potential error message to the user! Sim-
ply adding an <s:errors> tag under the message table and an error
message in the resource bundle does the trick:
Download email_19/web/WEB-INF/jsp/message_list.jsp
<div><s:errors field="selectedMessages"/></div>
Download email_19/res/StripesResources.properties
selectedMessages.valueNotPresent=You must select at least one message.
Now, clicking the Delete button with no selected checkbox gives an
error message, as shown here:
8.2
Select Boxes
To move the selected messages to a different folder, the user must first
select a folder. For that, we'll add a select box to the left of the Move
button:
 
 
 
Search WWH ::




Custom Search