001 package org.apache.myfaces.tobago.taglib.extension; 002 003 /* 004 * Licensed to the Apache Software Foundation (ASF) under one or more 005 * contributor license agreements. See the NOTICE file distributed with 006 * this work for additional information regarding copyright ownership. 007 * The ASF licenses this file to You under the Apache License, Version 2.0 008 * (the "License"); you may not use this file except in compliance with 009 * the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 */ 019 020 import org.apache.myfaces.tobago.apt.annotation.ExtensionTag; 021 import org.apache.myfaces.tobago.apt.annotation.Tag; 022 import org.apache.myfaces.tobago.taglib.component.SelectOneChoiceTag; 023 import org.apache.myfaces.tobago.taglib.decl.HasBinding; 024 import org.apache.myfaces.tobago.taglib.decl.HasConverter; 025 import org.apache.myfaces.tobago.taglib.decl.HasId; 026 import org.apache.myfaces.tobago.taglib.decl.HasLabel; 027 import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth; 028 import org.apache.myfaces.tobago.taglib.decl.HasOnchange; 029 import org.apache.myfaces.tobago.taglib.decl.HasTabIndex; 030 import org.apache.myfaces.tobago.taglib.decl.HasTip; 031 import org.apache.myfaces.tobago.taglib.decl.HasValidator; 032 import org.apache.myfaces.tobago.taglib.decl.HasValue; 033 import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener; 034 import org.apache.myfaces.tobago.taglib.decl.IsDisabled; 035 import org.apache.myfaces.tobago.taglib.decl.IsFocus; 036 import org.apache.myfaces.tobago.taglib.decl.IsInline; 037 import org.apache.myfaces.tobago.taglib.decl.IsReadonly; 038 import org.apache.myfaces.tobago.taglib.decl.IsRendered; 039 import org.apache.myfaces.tobago.taglib.decl.IsRequired; 040 import org.apache.myfaces.tobago.taglib.decl.HasMarkup; 041 042 import javax.servlet.jsp.JspException; 043 import javax.servlet.jsp.tagext.BodyTagSupport; 044 045 /** 046 * Render a single selection dropdown list with a label. 047 */ 048 049 @Tag(name = "selectOneChoice") 050 @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.SelectOneChoiceTag") 051 public class SelectOneChoiceExtensionTag 052 extends BodyTagSupport 053 implements HasId, HasValue, HasValueChangeListener, IsDisabled, 054 IsReadonly, HasOnchange, IsInline, HasLabel, HasLabelWidth, IsRequired, 055 IsRendered, IsFocus, HasBinding, HasTip, HasValidator, HasConverter, HasMarkup, HasTabIndex { 056 057 private String required; 058 private String value; 059 private String valueChangeListener; 060 private String disabled; 061 private String readonly; 062 private String onchange; 063 private String inline; 064 private String label; 065 private String rendered; 066 private String binding; 067 private String tip; 068 private String validator; 069 private String converter; 070 private String labelWidth; 071 private String tabIndex; 072 private String focus; 073 private String markup; 074 075 private LabelExtensionTag labelTag; 076 private SelectOneChoiceTag selectOneChoiceTag; 077 078 @Override 079 public int doStartTag() throws JspException { 080 081 labelTag = new LabelExtensionTag(); 082 labelTag.setPageContext(pageContext); 083 if (label != null) { 084 labelTag.setValue(label); 085 } 086 if (tip != null) { 087 labelTag.setTip(tip); 088 } 089 if (rendered != null) { 090 labelTag.setRendered(rendered); 091 } 092 if (labelWidth != null) { 093 labelTag.setColumns(labelWidth + ";*"); 094 } 095 if (markup != null) { 096 labelTag.setMarkup(markup); 097 } 098 labelTag.setParent(getParent()); 099 labelTag.doStartTag(); 100 101 selectOneChoiceTag = new SelectOneChoiceTag(); 102 selectOneChoiceTag.setPageContext(pageContext); 103 if (value != null) { 104 selectOneChoiceTag.setValue(value); 105 } 106 if (valueChangeListener != null) { 107 selectOneChoiceTag.setValueChangeListener(valueChangeListener); 108 } 109 if (validator != null) { 110 selectOneChoiceTag.setValidator(validator); 111 } 112 if (converter != null) { 113 selectOneChoiceTag.setConverter(converter); 114 } 115 if (binding != null) { 116 selectOneChoiceTag.setBinding(binding); 117 } 118 if (onchange != null) { 119 selectOneChoiceTag.setOnchange(onchange); 120 } 121 if (disabled != null) { 122 selectOneChoiceTag.setDisabled(disabled); 123 } 124 if (markup != null) { 125 selectOneChoiceTag.setMarkup(markup); 126 } 127 if (inline != null) { 128 selectOneChoiceTag.setInline(inline); 129 } 130 if (focus != null) { 131 selectOneChoiceTag.setFocus(focus); 132 } 133 if (id != null) { 134 selectOneChoiceTag.setId(id); 135 } 136 if (readonly != null) { 137 selectOneChoiceTag.setReadonly(readonly); 138 } 139 if (required != null) { 140 selectOneChoiceTag.setRequired(required); 141 } 142 if (tabIndex != null) { 143 selectOneChoiceTag.setTabIndex(tabIndex); 144 } 145 selectOneChoiceTag.setParent(labelTag); 146 selectOneChoiceTag.doStartTag(); 147 148 return super.doStartTag(); 149 } 150 151 @Override 152 public int doEndTag() throws JspException { 153 selectOneChoiceTag.doEndTag(); 154 labelTag.doEndTag(); 155 return super.doEndTag(); 156 } 157 158 @Override 159 public void release() { 160 super.release(); 161 binding = null; 162 onchange = null; 163 disabled = null; 164 inline = null; 165 label = null; 166 labelWidth = null; 167 converter = null; 168 validator = null; 169 readonly = null; 170 rendered = null; 171 required = null; 172 tip = null; 173 value = null; 174 valueChangeListener = null; 175 tabIndex = null; 176 selectOneChoiceTag = null; 177 labelTag = null; 178 focus = null; 179 markup = null; 180 } 181 182 public void setRequired(String required) { 183 this.required = required; 184 } 185 186 public void setValue(String value) { 187 this.value = value; 188 } 189 190 public void setValueChangeListener(String valueChangeListener) { 191 this.valueChangeListener = valueChangeListener; 192 } 193 194 public void setValidator(String validator) { 195 this.validator = validator; 196 } 197 198 public void setDisabled(String disabled) { 199 this.disabled = disabled; 200 } 201 202 public void setReadonly(String readonly) { 203 this.readonly = readonly; 204 } 205 206 public void setOnchange(String onchange) { 207 this.onchange = onchange; 208 } 209 210 public void setConverter(String converter) { 211 this.converter = converter; 212 } 213 214 public void setInline(String inline) { 215 this.inline = inline; 216 } 217 218 public void setLabel(String label) { 219 this.label = label; 220 } 221 222 public void setRendered(String rendered) { 223 this.rendered = rendered; 224 } 225 226 public void setBinding(String binding) { 227 this.binding = binding; 228 } 229 230 public void setTip(String tip) { 231 this.tip = tip; 232 } 233 234 public void setLabelWidth(String labelWidth) { 235 this.labelWidth = labelWidth; 236 } 237 238 public void setTabIndex(String tabIndex) { 239 this.tabIndex = tabIndex; 240 } 241 242 public void setFocus(String focus) { 243 this.focus = focus; 244 } 245 246 public void setMarkup(String markup) { 247 this.markup = markup; 248 } 249 }