KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > demo > tasklist > form > AddToListForm


1 /*
2 @COPYRIGHT@
3 */

4 package demo.tasklist.form;
5
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import org.apache.struts.action.ActionErrors;
8 import org.apache.struts.action.ActionForm;
9 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 JavaDoc newListItem;
20   private String JavaDoc errorMsg;
21   
22   public AddToListForm() {
23     super();
24     resetFields();
25   }
26
27   public ActionErrors validate(ActionMapping mapping, HttpServletRequest JavaDoc req ){
28     ActionErrors errors = new ActionErrors();
29     return errors;
30   }
31
32   public void reset(ActionMapping mapping, HttpServletRequest JavaDoc request) {
33     resetFields();
34   }
35
36   protected void resetFields() {
37     newListItem = "";
38     errorMsg = null;
39   }
40
41   public void setNewListItem(String JavaDoc nli) {
42     newListItem = nli;
43     errorMsg = null;
44     
45     if (newListItem == null ||
46     (newListItem = newListItem.trim()) == null ||
47      newListItem.equals("")) {
48       newListItem = null;
49       errorMsg = "Error: A new list item is required for \"Add\" operation";
50     }
51   }
52
53   public String JavaDoc getNewListItem() {
54     return newListItem;
55   }
56   
57   public String JavaDoc getErrorMsg(){
58     return errorMsg;
59   }
60 }
61
62
Popular Tags