1 64 65 package com.jcorporate.expresso.ext.struts.taglib.html; 66 67 73 74 import com.jcorporate.expresso.core.controller.Input; 75 import com.jcorporate.expresso.core.misc.StringUtil; 76 import com.jcorporate.expresso.ext.struts.taglib.ControllerUtils; 77 import org.apache.struts.util.ResponseUtils; 78 79 import javax.servlet.jsp.JspException ; 80 import java.util.Iterator ; 81 import java.util.List ; 82 import java.util.Vector ; 83 84 85 137 138 143 public class ExLayerInputTag extends ExLayerTag { 144 145 private String property = ""; 146 147 private String value = ""; 148 149 private List cascadedLayerControl = null; 150 151 private static String STR_JS_LAYER = "document.getElementById('%id%').style.display = '%action%';"; 152 153 154 private static String SHOW = "block"; 155 156 private static String HIDE = "none"; 157 158 159 162 public ExLayerInputTag() { 163 super(); 164 } 165 166 public int doStartTag() throws JspException { 167 if (!property.equals("")) { 168 String defaultValue = ""; 169 Input myInput = ControllerUtils.findInput(pageContext, property); 170 if (myInput == null) { 171 throw new JspException ("L'Input " + property + " n'est pas dans la response "); 172 } else { 173 defaultValue = myInput.getDefaultValue(); 174 if (defaultValue.equals(value)) { 175 setState("SHOW"); 176 } else { 177 setState("HIDE"); 178 } 179 } 180 } 181 return super.doStartTag(); 182 } 183 184 189 public int doEndTag() throws JspException { 190 int retIntSuper = super.doEndTag(); 191 String resultShow = ""; 192 String resultHide = ""; 193 String result = ""; 194 195 resultShow += "function showLayer" + getId() + "(expand){\n"; 196 resultHide += "function hideLayer" + getId() + "(expand){\n"; 197 198 if (cascadedLayerControl != null) { 200 Iterator itCascadeLayer = cascadedLayerControl.iterator(); 201 boolean isCascadePresent = false; 202 if (itCascadeLayer.hasNext()) { 203 resultShow += " if( expand == \"EXPAND\"){\n"; 204 resultHide += " if( expand == \"EXPAND\"){\n"; 205 isCascadePresent = true; 206 } 207 while (itCascadeLayer.hasNext()) { 208 String idLayerControl = (String ) itCascadeLayer.next(); 209 resultShow += " showLayer" + idLayerControl + "('EXPAND');\n"; 210 resultHide += " hideLayer" + idLayerControl + "('EXPAND');\n"; 211 } 212 if (isCascadePresent) { 213 resultShow += " }\n"; 214 resultHide += " }\n"; 215 } 216 217 } 218 219 String jsShow = STR_JS_LAYER; 220 String jsHide = ""; 221 222 jsShow = StringUtil.replaceString(jsShow, "%id%", getId()); 223 jsHide = (jsShow); 224 225 String action = SHOW; 226 jsShow = StringUtil.replaceString(jsShow, "%action%", action); 227 action = HIDE; 228 jsHide = StringUtil.replaceString(jsHide, "%action%", action); 229 230 resultShow += " " + jsShow + "\n"; 231 resultHide += " " + jsHide + "\n"; 232 resultShow += "}"; 233 resultHide += "}"; 234 235 result += "\n<script language=\"JavaScript1.2\">\n"; 236 result += resultShow + "\n"; 237 result += resultHide + "\n"; 238 result += "</script>\n"; 239 ResponseUtils.write(pageContext, result); 240 return retIntSuper; 241 } 242 243 244 249 public String getProperty() { 250 return property; 251 } 252 253 258 public void setProperty(String property) { 259 this.property = property; 260 } 261 262 263 268 public String getValue() { 269 return value; 270 } 271 272 277 public void setValue(String value) { 278 this.value = value; 279 } 280 281 282 288 public boolean addLayerToHide(String idLayer) { 289 if (cascadedLayerControl == null) { 290 cascadedLayerControl = new Vector (); 291 } 292 return cascadedLayerControl.add(idLayer); 293 } 294 295 296 } 297 298 | Popular Tags |