1 13 package com.tonbeller.wcf.form; 14 15 import javax.servlet.http.HttpSession ; 16 17 import org.apache.log4j.Logger; 18 import org.w3c.dom.Element ; 19 20 import com.tonbeller.wcf.controller.RequestContext; 21 import com.tonbeller.wcf.controller.RequestListener; 22 import com.tonbeller.wcf.scroller.Scroller; 23 import com.tonbeller.wcf.ui.Button; 24 25 58 59 public class ButtonHandler implements NodeHandler, RequestListener { 60 61 private XmlComponent comp; 62 private Element element; 63 private boolean pressed = false; 64 private boolean success = true; 65 66 public static final String NO_ACTION = ""; 67 public static final String VALIDATE_ACTION = "validate"; 68 public static final String REVERT_ACTION = "revert"; 69 private static Logger logger = Logger.getLogger(ButtonHandler.class); 70 71 72 public void initialize(RequestContext context, XmlComponent comp, Element element) { 73 this.comp = comp; 74 this.element = element; 75 comp.getDispatcher().addRequestListener(Button.getId(element), null, this); 76 } 77 78 public void destroy(HttpSession session) { 79 } 80 81 84 public void request(RequestContext context) throws Exception { 85 if(element.getAttribute("scroller")!=null) 86 Scroller.enableScroller(context); 87 88 pressed = true; 89 success = true; 90 String action = element.getAttribute("action"); 91 if (action.equals("revert")) 92 comp.revert(context); 93 else if (action.equals("validate")) 94 success = comp.validate(context); 95 if (success) { 96 97 boolean hide = "true".equals(element.getAttribute("hide")); 98 if (hide) 99 comp.setVisible(false); 100 101 String forward = element.getAttribute("forward"); 102 if (forward != null && forward.length() > 0) 103 comp.setNextView(forward); 104 105 String successAttr = element.getAttribute("successAttr"); 106 if (successAttr.length() > 0) 107 context.getRequest().setAttribute(successAttr, "true"); 108 } 109 } 110 111 112 public void render(RequestContext context) throws Exception { 113 } 114 115 } 116 | Popular Tags |