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