1 64 65 package com.jcorporate.expresso.ext.struts.taglib.html; 66 67 import com.jcorporate.expresso.core.controller.ControllerElement; 68 import com.jcorporate.expresso.core.controller.Transition; 69 import com.jcorporate.expresso.core.misc.StringUtil; 70 import com.jcorporate.expresso.ext.struts.taglib.ControllerUtils; 71 import org.apache.struts.taglib.html.ButtonTag; 72 import org.apache.struts.taglib.html.Constants; 73 import org.apache.struts.util.ResponseUtils; 74 75 import javax.servlet.jsp.JspException ; 76 import java.util.Hashtable ; 77 78 79 82 public class ExButtonTag 83 extends ButtonTag { 84 protected String name = null; 85 86 87 public String getName() { 88 return (this.name); 89 } 90 91 public void setName(String name) { 92 this.name = name; 93 } 94 95 101 public int doStartTag() 102 throws JspException { 103 Transition myTransition = null; 104 String nameToUse = name; 105 String propertyToUse = null; 106 107 if (StringUtil.notNull(nameToUse).equals(Constants.BEAN_KEY)) { 108 nameToUse = null; 109 } 110 if (nameToUse == null) { 111 myTransition = ControllerUtils.findTransition(pageContext, 112 propertyToUse); 113 } else { 114 ControllerElement ce = ControllerUtils.findElement(pageContext, 115 nameToUse, 116 propertyToUse); 117 118 if (ce instanceof Transition) { 119 myTransition = (Transition) ce; 120 } else { 121 throw new JspException ("Element '" + propertyToUse + 122 "' in bean '" + nameToUse + 123 "' is not a transition element - it is a '" + 124 ce.getClass().getName() + "'"); 125 } 126 } 127 128 Hashtable params = myTransition.getParams(); 129 130 if (params != null) { 131 132 ResponseUtils.write(pageContext, 134 myTransition.getHTMLParamString() + "\n"); 135 } 136 137 this.text = null; 138 139 String label = value; 141 142 if ((label == null) && (text != null)) { 143 label = text; 144 } 145 if ((label == null) || (label.trim().length() < 1)) { 146 label = "Click"; 147 } 148 149 StringBuffer results = new StringBuffer (); 151 results.append("<button type=\"submit\""); 152 153 if (property != null) { 154 results.append(" name=\"button_"); 155 results.append(myTransition.getName()); 156 results.append("\""); 157 } 158 if (accesskey != null) { 159 results.append(" accesskey=\""); 160 results.append(accesskey); 161 results.append("\""); 162 } 163 if (tabindex != null) { 164 results.append(" tabindex=\""); 165 results.append(tabindex); 166 results.append("\""); 167 } 168 169 results.append(" value=\""); 170 results.append(label); 171 results.append("\""); 172 results.append(prepareEventHandlers()); 173 results.append(prepareStyles()); 174 results.append(">"); 175 176 ResponseUtils.write(pageContext, results.toString()); 178 179 return (EVAL_BODY_INCLUDE); 180 } 181 182 188 public int doEndTag() 189 throws JspException { 190 191 StringBuffer results = new StringBuffer ("</button>"); 193 194 ResponseUtils.write(pageContext, results.toString()); 196 197 return (EVAL_PAGE); 199 } 200 } | Popular Tags |