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