01: /*
02: @COPYRIGHT@
03: */
04: package demo.tasklist.form;
05:
06: import java.util.ArrayList;
07: import javax.servlet.http.HttpServletRequest;
08: import org.apache.struts.action.ActionErrors;
09: import org.apache.struts.action.ActionForm;
10: import org.apache.struts.action.ActionMapping;
11: import org.apache.struts.action.ActionMessage;
12: import org.apache.struts.action.ActionMessages;
13:
14: /**
15: * DeleteFromListForm represents the form data submitted from the display page.
16: * The ActionServlet populates this form when a request for deletion is received
17: * from the display page.
18: */
19: public class DeleteFromListForm extends ActionForm {
20: private ArrayList itemsForDelete = new ArrayList();
21: private String errorMsg;
22:
23: public DeleteFromListForm() {
24: super ();
25: resetFields();
26: }
27:
28: public ActionErrors validate(ActionMapping mapping,
29: HttpServletRequest req) {
30: ActionErrors errors = new ActionErrors();
31: return errors;
32: }
33:
34: public void reset(ActionMapping mapping, HttpServletRequest request) {
35: resetFields();
36: }
37:
38: protected void resetFields() {
39: errorMsg = "Error: At least one item for deletion must be selected for \"Delete\" operation";
40: itemsForDelete = new ArrayList();
41: }
42:
43: public String[] getItemsForDelete() {
44: return (String[]) this .itemsForDelete.toArray(new String[0]);
45: }
46:
47: public void setItemsForDelete(String[] itemsForDelete) {
48: if (itemsForDelete == null || itemsForDelete.length == 0) {
49: itemsForDelete = null;
50: } else {
51: errorMsg = null;
52: for (int i = 0; i < itemsForDelete.length; i++) {
53: this .itemsForDelete.add(itemsForDelete[i]);
54: }
55: }
56: }
57:
58: public String getErrorMsg() {
59: return errorMsg;
60: }
61: }
|