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 javax.servlet.http.HttpServletRequest;
11 import org.apache.struts.action.ActionErrors;
12 import org.apache.struts.action.ActionForm;
13 import org.apache.struts.action.ActionMapping;
14 import org.apache.struts.action.ActionMessage;
15 import org.apache.struts.action.ActionMessages;
16
17 /**
18 * AddToListForm represents the form data submitted from the display page.
19 * The ActionServlet populates this form when a request for add is received
20 * from the display page.
21 *
22 *@author Terracotta, Inc.
23 */
24 public class AddToListForm extends ActionForm {
25 private String newListItem;
26 private String errorMsg;
27
28 public AddToListForm() {
29 super();
30 resetFields();
31 }
32
33 public void setNewListItem(String nli) {
34 newListItem = nli;
35 errorMsg = null;
36
37 if (newListItem == null ||
38 (newListItem = newListItem.trim()) == null ||
39 newListItem.equals("")) {
40 newListItem = null;
41 errorMsg = "Error: A new list item is required for \"Add\" operation";
42 }
43 }
44
45 public String getNewListItem() {
46 return newListItem;
47 }
48
49 public String getErrorMsg() {
50 return errorMsg;
51 }
52
53 public ActionErrors validate(ActionMapping mapping, HttpServletRequest req) {
54 ActionErrors errors = new ActionErrors();
55 return errors;
56 }
57
58 public void reset(ActionMapping mapping, HttpServletRequest request) {
59 resetFields();
60 }
61
62 protected void resetFields() {
63 newListItem = "";
64 errorMsg = null;
65 }
66 }
|