1 18 package org.apache.beehive.netui.tags.html; 19 20 import org.apache.beehive.netui.tags.IHtmlAccessable; 21 import org.apache.beehive.netui.tags.rendering.*; 22 import org.apache.beehive.netui.util.Bundle; 23 24 import javax.servlet.ServletRequest ; 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.tagext.Tag ; 28 29 46 public class RadioButtonOption 47 extends HtmlFocusBaseTag 48 implements IHtmlAccessable 49 { 50 private InputBooleanTag.State _state = new InputBooleanTag.State(); 51 private SpanTag.State _spanState = new SpanTag.State(); 52 private String _text; 53 54 57 public String getTagName() 58 { 59 return "RadioButtonOption"; 60 } 61 62 67 protected AbstractHtmlState getState() 68 { 69 return _state; 70 } 71 72 78 public void setAttribute(String name, String value, String facet) 79 throws JspException 80 { 81 if (name != null) { 82 if (name.equals(TYPE) || name.equals(VALUE) || name.equals(CHECKED)) { 83 String s = Bundle.getString("Tags_AttributeMayNotBeSet", new Object []{name}); 84 registerTagError(s, null); 85 } 86 else { 87 _state.disabled = new Boolean (value).booleanValue(); 88 return; 89 } 90 } 91 super.setAttribute(name, value, facet); 92 } 93 94 104 public void setLabelStyle(String labelStyle) 105 { 106 _spanState.style = setNonEmptyValueAttribute(labelStyle); 107 } 108 109 119 public void setLabelStyleClass(String labelStyleClass) 120 { 121 _spanState.styleClass = setNonEmptyValueAttribute(labelStyleClass); 122 } 123 124 133 public void setValue(Object value) 134 throws JspException 135 { 136 if (value != null) 137 _state.value = value.toString(); 138 else 139 _state.value = null; 140 } 141 142 146 public int doStartTag() throws JspException 147 { 148 149 Tag parentTag = findAncestorWithClass(this, RadioButtonGroup.class); 150 if (parentTag == null) { 151 String s = Bundle.getString("Tags_RadioButtonOptionNoRadioButtonGroup"); 152 registerTagError(s, null); 153 return SKIP_BODY; 154 } 155 156 RadioButtonGroup parent = (RadioButtonGroup) parentTag; 157 if ((parent.getOptionsDataSource() != null) && !parent.isRepeater()) { 158 String s = Bundle.getString("Tags_RadioOptionParentHasOptionsDataSource"); 159 parent.registerTagError(s, null); 160 return SKIP_BODY; 161 } 162 163 return EVAL_BODY_BUFFERED; 164 165 } 166 167 171 public int doAfterBody() throws JspException 172 { 173 String text = bodyContent.getString(); 174 if (text != null) { 175 text = text.trim(); 176 bodyContent.clearBody(); 177 if (text.length() > 0) 178 _text = text; 179 } 180 return SKIP_BODY; 181 } 182 183 187 public int doEndTag() throws JspException 188 { 189 if (hasErrors()) 190 return reportAndExit(EVAL_PAGE); 191 192 ServletRequest req = pageContext.getRequest(); 193 ConstantRendering cr = TagRenderingBase.Factory.getConstantRendering(req); 194 195 RadioButtonGroup parent = (RadioButtonGroup) findAncestorWithClass(this, RadioButtonGroup.class); 197 assert(parent != null); 198 boolean repeat = parent.isRepeater(); 199 200 WriteRenderAppender writer = new WriteRenderAppender(pageContext); 202 if (parent.isVertical()) { 203 cr.TR_TD(writer); 204 } 205 _state.type = INPUT_RADIO; 206 _state.name = parent.getQualifiedDataSourceName(); 207 if (_state.id != null) { 208 String tagId = _state.id; 209 _state.id = getIdForTagId(_state.id); 210 String script = renderDefaultNameAndId((HttpServletRequest ) req, _state, tagId, _state.name); 211 if (script != null) { 212 write(script); 213 } 214 } 215 216 _state.checked = new Boolean (parent.isMatched(_state.value, null)).booleanValue(); 218 _state.disabled = isDisabled(); 219 if (!_state.disabled) 220 _state.disabled = parent.isDisabled(); 221 222 TagRenderingBase br = TagRenderingBase.Factory.getRendering(TagRenderingBase.INPUT_BOOLEAN_TAG, req); 223 br.doStartTag(writer, _state); 224 225 if (repeat) { 227 localRelease(); 228 return EVAL_PAGE; 229 } 230 231 if (_spanState.style == null) { 232 _spanState.style = parent.getLabelStyle(); 233 } 234 if (_spanState.styleClass == null) { 235 _spanState.styleClass = parent.getLabelStyleClass(); 236 } 237 238 TagRenderingBase spanTag = TagRenderingBase.Factory.getRendering(TagRenderingBase.SPAN_TAG, req); 239 spanTag.doStartTag(writer, _spanState); 240 if (_text == null) 241 write(_state.value); 242 else 243 write(_text); 244 spanTag.doEndTag(writer); 245 246 if (parent.isVertical()) { 247 cr.end_TD_TR(writer); 248 } 249 250 localRelease(); 252 return EVAL_PAGE; 253 254 } 255 256 259 protected void localRelease() 260 { 261 super.localRelease(); 262 263 _state.clear(); 264 _spanState.clear(); 265 266 _text = null; 267 } 268 269 275 293 public void setAccessKey(char accessKey) 294 { 295 _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ACCESSKEY, Character.toString(accessKey)); 296 } 297 298 307 public void setAlt(String alt) 308 { 309 _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, ALT, alt); 310 } 311 312 323 public void setTabindex(int tabindex) 324 { 325 _state.registerAttribute(AbstractHtmlState.ATTR_GENERAL, TABINDEX, Integer.toString(tabindex)); 326 } 327 } 328 | Popular Tags |