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