01 /*
02 *
03 * All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
04 *
05 */
06 package demo.tasklist.form;
07
08 import javax.servlet.http.HttpServletRequest;
09 import org.apache.struts.action.ActionErrors;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionMapping;
12 import org.apache.struts.action.ActionMessage;
13 import org.apache.struts.action.ActionMessages;
14
15 /**
16 * AddToListForm represents the form data submitted from the display page.
17 * The ActionServlet populates this form when a request for add is received
18 * from the display page.
19 */
20 public class AddToListForm extends ActionForm {
21 private String newListItem;
22 private String errorMsg;
23
24 public AddToListForm() {
25 super();
26 resetFields();
27 }
28
29 public ActionErrors validate(ActionMapping mapping, 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 newListItem = "";
40 errorMsg = null;
41 }
42
43 public void setNewListItem(String nli) {
44 newListItem = nli;
45 errorMsg = null;
46
47 if (newListItem == null ||
48 (newListItem = newListItem.trim()) == null ||
49 newListItem.equals("")) {
50 newListItem = null;
51 errorMsg = "Error: A new list item is required for \"Add\" operation";
52 }
53 }
54
55 public String getNewListItem() {
56 return newListItem;
57 }
58
59 public String getErrorMsg(){
60 return errorMsg;
61 }
62 }
|