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 com.jcorporate.expresso.ext.taglib.MessageUtil; 72 import org.apache.struts.taglib.html.Constants; 73 import org.apache.struts.taglib.html.SubmitTag; 74 import org.apache.struts.util.ResponseUtils; 75 76 import javax.servlet.jsp.JspException ; 77 import java.util.Hashtable ; 78 79 80 85 public class ExSubmitTag 86 extends SubmitTag { 87 protected String name = null; 88 89 90 public String getName() { 91 return (this.name); 92 } 93 94 public void setName(String name) { 95 this.name = name; 96 } 97 104 public int doStartTag() 105 throws JspException { 106 Transition myTransition = null; 107 String nameToUse = name; 108 109 if (StringUtil.notNull(nameToUse).equals(Constants.BEAN_KEY)) { 110 nameToUse = null; 111 } 112 113 ControllerElement ce = ControllerUtils.findElement(pageContext, 114 nameToUse, 115 property); 116 117 if (ce instanceof Transition) { 118 myTransition = (Transition) ce; 119 } else { 120 if (ce == null) { 121 throw new JspException ("Unable to find element: " + nameToUse 122 + " and property" + property); 123 124 } else { 125 throw new JspException ("Element '" + property + "' in bean '" + 126 nameToUse + 127 "' is not a transition element - it is a '" + 128 ce.getClass().getName() + "'"); 129 } 130 } 131 132 133 Hashtable params = myTransition.getParams(); 134 135 if (params != null) { 136 137 ResponseUtils.write(pageContext, 139 myTransition.getHTMLParamString() + "\n"); 140 } 141 142 this.text = null; 143 144 return (EVAL_BODY_BUFFERED); 146 } 147 148 154 public int doAfterBody() 155 throws JspException { 156 if (bodyContent != null) { 157 String value = bodyContent.getString().trim(); 158 159 if (value.length() > 0) { 160 text = value; 161 } 162 } 163 164 return (SKIP_BODY); 165 } 166 167 173 public int doEndTag() 174 throws JspException { 175 Transition myTransition = null; 176 String nameToUse = name; 177 178 ControllerElement ce = ControllerUtils.findElement(pageContext, 179 nameToUse, 180 property); 181 182 if (ce instanceof Transition) { 183 myTransition = (Transition) ce; 184 } else { 185 throw new JspException ("Element '" + property + "' in bean '" + 186 nameToUse + 187 "' is not a transition element - it is a '" + 188 ce.getClass().getName() + "'"); 189 } 190 191 String label = value; 193 194 if ((label == null) && (text != null)) { 195 label = text; 196 } 197 if ((label == null) || (label.length() < 1)) { 198 label = myTransition.getLabel(); 199 } 200 201 StringBuffer results = new StringBuffer (); 203 results.append("<input type=\"submit\" name=\""); 204 results.append("button_" + myTransition.getName()); 205 results.append("\""); 206 207 if (accesskey != null) { 208 results.append(" accesskey=\""); 209 results.append(accesskey); 210 results.append("\""); 211 } 212 if (tabindex != null) { 213 results.append(" tabindex=\""); 214 results.append(tabindex); 215 results.append("\""); 216 } 217 218 results.append(" value=\""); 219 results.append(MessageUtil.getString(pageContext, label)); 220 results.append("\""); 221 results.append(prepareEventHandlers()); 222 results.append(prepareStyles()); 223 results.append(">"); 224 225 ResponseUtils.write(pageContext, results.toString()); 227 228 return (EVAL_PAGE); 230 } 231 } | Popular Tags |