1 4 package demo.tasklist.form; 5 6 import java.util.ArrayList ; 7 import javax.servlet.http.HttpServletRequest ; 8 import org.apache.struts.action.ActionErrors; 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionMapping; 11 import org.apache.struts.action.ActionMessage; 12 import org.apache.struts.action.ActionMessages; 13 14 19 public class DeleteFromListForm extends ActionForm { 20 private ArrayList itemsForDelete = new ArrayList (); 21 private String errorMsg; 22 23 public DeleteFromListForm() { 24 super(); 25 resetFields(); 26 } 27 28 public ActionErrors validate(ActionMapping mapping, 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 errorMsg = "Error: At least one item for deletion must be selected for \"Delete\" operation"; 39 itemsForDelete = new ArrayList (); 40 } 41 42 public String [] getItemsForDelete() { 43 return (String [])this.itemsForDelete.toArray(new String [0]); 44 } 45 46 public void setItemsForDelete(String [] itemsForDelete) { 47 if (itemsForDelete == null || itemsForDelete.length == 0) { 48 itemsForDelete = null; 49 } else { 50 errorMsg = null; 51 for (int i = 0; i < itemsForDelete.length; i++) { 52 this.itemsForDelete.add(itemsForDelete[i]); 53 } 54 } 55 } 56 57 public String getErrorMsg(){ 58 return errorMsg; 59 } 60 } 61 62 | Popular Tags |