1 18 package org.apache.beehive.netui.tags.html; 19 20 22 import org.apache.beehive.netui.tags.IHtmlAccessable; 23 import org.apache.beehive.netui.tags.rendering.*; 24 import org.apache.beehive.netui.util.Bundle; 25 26 import javax.servlet.ServletRequest ; 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.jsp.JspException ; 29 import javax.servlet.jsp.tagext.Tag ; 30 31 33 52 public class CheckBoxOption extends HtmlFocusBaseTag 53 implements IHtmlAccessable 54 { 55 private InputBooleanTag.State _state = new InputBooleanTag.State(); 56 private SpanTag.State _spanState = new SpanTag.State(); 57 private String _text; private Boolean _defaultValue; 59 60 63 public String getTagName() 64 { 65 return "CheckBoxOption"; 66 } 67 68 73 protected AbstractHtmlState getState() 74 { 75 return _state; 76 } 77 78 86 public void setAttribute(String name, String value, String facet) 87 throws JspException 88 { 89 if (name != null) { 90 if (name.equals(TYPE) || name.equals(VALUE) || name.equals(CHECKED)) { 91 String s = Bundle.getString("Tags_AttributeMayNotBeSet", new Object []{name}); 92 registerTagError(s, null); 93 } 94 else { 95 _state.disabled = new Boolean (value).booleanValue(); 96 return; 97 } 98 } 99 super.setAttribute(name, value, facet); 100 } 101 102 112 public void setLabelStyle(String labelStyle) 113 { 114 _spanState.style = setNonEmptyValueAttribute(labelStyle); 115 } 116 117 127 public void setLabelStyleClass(String labelStyleClass) 128 { 129 _spanState.styleClass = setNonEmptyValueAttribute(labelStyleClass); 130 } 131 132 143 public void setValue(Object value) 144 throws JspException 145 { 146 if (value != null) 147 _state.value = value.toString(); 148 else 149 _state.value = null; 150 } 151 152 161 public void setDefaultValue(boolean defaultValue) 162 throws JspException 163 { 164 _defaultValue = Boolean.valueOf(defaultValue); 165 } 166 167 171 public int doStartTag() throws JspException 172 { 173 Tag parentTag = findAncestorWithClass(this, CheckBoxGroup.class); 175 if (parentTag == null) { 176 String s = Bundle.getString("Tags_CheckBoxOptionNoCheckBoxGroup"); 177 registerTagError(s, null); 178 return SKIP_BODY; 179 } 180 181 CheckBoxGroup parent = (CheckBoxGroup) parentTag; 182 if ((parent.getOptionsDataSource() != null && !parent.isRepeater())) { 183 String s = Bundle.getString("Tags_CheckBoxOptionParentHasOptionsDataSource"); 184 parent.registerTagError(s, null); 185 return SKIP_BODY; 186 } 187 188 return EVAL_BODY_BUFFERED; 190 } 191 192 196 public int doAfterBody() throws JspException 197 { 198 String text = bodyContent.getString(); 199 if (text != null) { 200 bodyContent.clearBody(); 201 text = text.trim(); 202 if (text.length() > 0) 203 _text = text; 204 } 205 return SKIP_BODY; 206 } 207 208 212 public int doEndTag() throws JspException 213 { 214 if (hasErrors()) 215 return reportAndExit(EVAL_PAGE); 216 217 ServletRequest req = pageContext.getRequest(); 219 CheckBoxGroup parent = (CheckBoxGroup) findAncestorWithClass(this, CheckBoxGroup.class); 220 ConstantRendering cr = TagRenderingBase.Factory.getConstantRendering(req); 221 boolean repeat = parent.isRepeater(); 222 223 WriteRenderAppender writer = new WriteRenderAppender(pageContext); 225 if (!repeat && parent.isVertical()) { 226 cr.TR_TD(writer); 227 } 228 229 230 _state.type = INPUT_CHECKBOX; 231 _state.name = parent.getQualifiedDataSourceName(); 232 if (_state.id != null) { 233 String tagId = _state.id; 234 _state.id = getIdForTagId(_state.id); 235 241 String script = renderDefaultNameAndId((HttpServletRequest ) req, _state, tagId, _state.name); 242 if (script != null) { 243 write(script); 244 } 245 } 246 247 if (parent.isMatched(_state.value, _defaultValue)) 251 _state.checked = true; 252 _state.disabled = isDisabled(); 253 if (!_state.disabled) 254 _state.disabled = parent.isDisabled(); 255 256 TagRenderingBase br = TagRenderingBase.Factory.getRendering(TagRenderingBase.INPUT_BOOLEAN_TAG, req); 257 br.doStartTag(writer, _state); 258 br.doEndTag(writer); 259 260 if (repeat && !parent.isDisabled()) { 261 parent.createHiddenField(writer); 262 } 263 264 if (repeat) { 266 localRelease(); 268 return EVAL_PAGE; 269 } 270 271 if (_spanState.style == null) { 272 _spanState.style = parent.getLabelStyle(); 273 } 274 if (_spanState.styleClass == null) { 275 _spanState.styleClass = parent.getLabelStyleClass(); 276 } 277 278 TagRenderingBase spanTag = TagRenderingBase.Factory.getRendering(TagRenderingBase.SPAN_TAG, req); 279 spanTag.doStartTag(writer, _spanState); 280 if (_text == null) 281 write(_state.value); 282 else 283 write(_text); 284 spanTag.doEndTag(writer); 285 286 if (parent.isVertical()) { 287 cr.end_TD_TR(writer); 288 } 289 290 localRelease(); 292 return EVAL_PAGE; 293 294 } 295 296 299 protected void localRelease() 300 { 301 super.localRelease(); 302 303 _state.clear(); 304 _spanState.clear(); 305 _text = null; 306 } 307 308 314 315 333 public void setAccessKey(char accessKey) 334 { 335 _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ACCESSKEY, Character.toString(accessKey)); 336 } 337 338 347 public void setAlt(String alt) 348 { 349 _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALT, alt); 350 } 351 352 363 public void setTabindex(int tabindex) 364 { 365 _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TABINDEX, Integer.toString(tabindex)); 366 } 367 } 368 | Popular Tags |