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.Input; 69 import com.jcorporate.expresso.core.misc.StringUtil; 70 import com.jcorporate.expresso.ext.struts.taglib.ControllerUtils; 71 import org.apache.struts.taglib.html.CheckboxTag; 72 import org.apache.struts.util.ResponseUtils; 73 74 import javax.servlet.jsp.JspException ; 75 76 77 83 public class ExCheckboxTag 84 extends CheckboxTag { 85 92 public int doStartTag() 93 throws JspException { 94 Input myInput = null; 95 String nameToUse = name; 96 String propertyToUse = property; 97 98 if (StringUtil.notNull(nameToUse).equals("org.apache.struts.taglib.html.BEAN")) { 99 nameToUse = null; 100 } 101 if (nameToUse == null) { 102 myInput = ControllerUtils.findInput(pageContext, propertyToUse); 103 } else { 104 ControllerElement ce = ControllerUtils.findElement(pageContext, 105 nameToUse, 106 propertyToUse); 107 108 if (ce == null) { 109 throw new JspException ("No such element as '" + 110 StringUtil.notNull(propertyToUse) + 111 "' in element '" + 112 StringUtil.notNull(nameToUse) + "'"); 113 } 114 if (ce instanceof Input) { 115 myInput = (Input) ce; 116 } else { 117 throw new JspException ("Element '" + 118 StringUtil.notNull(propertyToUse) + 119 "' in bean '" + 120 StringUtil.notNull(nameToUse) + 121 "' is not an Input - it is a '" + 122 ce.getClass().getName() + "'"); 123 } 124 } 125 126 StringBuffer results = new StringBuffer ("<input type=\"checkbox\""); 128 results.append(" name=\""); 129 results.append(myInput.getName()); 130 results.append("\""); 131 132 if (accesskey != null) { 133 results.append(" accesskey=\""); 134 results.append(accesskey); 135 results.append("\""); 136 } 137 if (tabindex != null) { 138 results.append(" tabindex=\""); 139 results.append(tabindex); 140 results.append("\""); 141 } 142 143 results.append(" value=\""); 144 145 if (value == null) { 146 results.append("Y"); 147 } else { 148 results.append(value); 149 } 150 151 results.append("\""); 152 153 String checked = myInput.getDefaultValue(); 154 155 if (checked.equalsIgnoreCase("true") || 156 checked.equalsIgnoreCase("yes") || 157 checked.equalsIgnoreCase("on") || checked.equalsIgnoreCase("y") || 158 checked.equalsIgnoreCase(value)) { 159 results.append(" checked=\"checked\""); 160 } 161 162 results.append(prepareEventHandlers()); 163 results.append(prepareStyles()); 164 results.append(">"); 165 166 ResponseUtils.write(pageContext, results.toString()); 168 169 this.text = null; 171 172 return (EVAL_BODY_TAG); 173 } 174 } | Popular Tags |