1 7 package com.inversoft.verge.mvc.test; 8 9 10 import java.util.ArrayList ; 11 import java.util.Collections ; 12 import java.util.List ; 13 14 import org.apache.log4j.Logger; 15 16 import com.inversoft.beans.BeanException; 17 import com.inversoft.verge.mvc.controller.form.FormAction; 18 import com.inversoft.verge.mvc.controller.form.config.FormConfig; 19 20 21 30 public class SimpleActionHandler { 31 32 35 private static final Logger logger = Logger.getLogger(SimpleActionHandler.class); 36 37 38 41 public SimpleActionHandler() { 42 super(); 43 } 44 45 46 public String handleSetUpUser(FormAction action) { 47 logger.debug("Action: " + action.getAction()); 48 49 FormConfig config = action.getFormConfig(); 50 if (config != null) { 51 logger.debug("Form based MVC call"); 52 53 Object bean = null; 54 try { 55 bean = config.getFormBean("user").getInstance(action.getHttpServletRequest()); 56 } catch (BeanException be) { 57 logger.error(be); 58 } 59 60 if (bean != null) { 61 logger.debug("bean: " + bean.toString()); 62 } 63 } 64 65 return "success"; 66 } 67 68 public String handleSetUpAddress(FormAction action) throws BeanException { 69 logger.debug("Action: " + action.getAction()); 70 71 FormConfig config = action.getFormConfig(); 72 if (config != null) { 73 logger.debug("Form based MVC call"); 74 75 Address addr = (Address) action.getFormBean("address"); 76 77 if (addr != null) { 78 logger.debug("bean: " + addr.toString()); 79 } 80 81 addr.setCity("Changed the city"); 82 } 83 84 return "failure"; 85 } 86 87 public String handleCountrySelect(FormAction action) throws BeanException { 88 Address addr = (Address) action.getFormBean("address"); 89 if (addr.getCountry().equals("USA")) { 90 addr.setCities(new String [] {"Denver", "Chicago"}); 91 } else if (addr.getCountry().equals("Canada")) { 92 addr.setCities(new String [] {"Ontario", "Quebec"}); 93 } else { 94 addr.setCities(null); 95 } 96 return "success"; 97 } 98 99 public String handleFinished(FormAction action) throws BeanException { 100 Address addr = (Address) action.getFormBean("address"); 101 if (addr != null) { 102 logger.debug("Address: " + addr.toString()); 103 } 104 return "success"; 105 } 106 107 public String handleLongTxnAction(FormAction action) throws InterruptedException { 108 List list = new ArrayList (); 110 111 for (int i = 0; i < 10000; i++) { 112 String s = "" + i; 113 s += s + "" + i + "" + i; 114 list.add(s); 115 Collections.sort(list); 116 } 117 return "done"; 118 } 119 120 public String handleGlobalAction1(FormAction action) throws BeanException { 121 return "globalMapping1"; 122 } 123 } | Popular Tags |