AddToListForm.java
01 /*
02  *
03  * All content copyright Terracotta, Inc., unless otherwise indicated. All rights reserved.
04  *
05 */
06 package demo.townsend.form;
07 
08 import javax.servlet.http.HttpServletRequest;
09 
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  * AddToListForm represents the form data submitted from the display page.  
18  * The ActionServlet populates this form when a request for add is received 
19  * from the display page.
20  */
21 public class AddToListForm extends ActionForm {
22    
23   //private Product product;
24   private String id;
25   
26   public AddToListForm() {
27     super();
28     resetFields();
29   }
30 
31   public ActionErrors validate(ActionMapping mapping, HttpServletRequest req ){
32      
33      ActionErrors errors = new ActionErrors();
34 
35     if(id == null) {
36       errors.add(ActionMessages.GLOBAL_MESSAGE, 
37             new ActionMessage("global.error.addtolist.requiredfield""product" ));
38     }
39     return errors;
40   }
41 
42   public void reset(ActionMapping mapping, HttpServletRequest request) {
43     resetFields();
44   }
45 
46   protected void resetFields() {
47     id = "";
48   }
49 
50   public void setId(String id) {
51     this.id = id;
52   }
53 
54   public String getId() {
55     return id;
56   }
57 }