1 4 package demo.tasklist.form; 5 6 import javax.servlet.http.HttpServletRequest ; 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 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, HttpServletRequest req ){ 28 ActionErrors errors = new ActionErrors(); 29 return errors; 30 } 31 32 public void reset(ActionMapping mapping, HttpServletRequest request) { 33 resetFields(); 34 } 35 36 protected void resetFields() { 37 newListItem = ""; 38 errorMsg = null; 39 } 40 41 public void setNewListItem(String 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 getNewListItem() { 54 return newListItem; 55 } 56 57 public String getErrorMsg(){ 58 return errorMsg; 59 } 60 } 61 62 | Popular Tags |