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 labelTag.setParent(getParent()); 096 labelTag.doStartTag(); 097 098 selectOneChoiceTag = new SelectOneChoiceTag(); 099 selectOneChoiceTag.setPageContext(pageContext); 100 if (value != null) { 101 selectOneChoiceTag.setValue(value); 102 } 103 if (valueChangeListener != null) { 104 selectOneChoiceTag.setValueChangeListener(valueChangeListener); 105 } 106 if (validator != null) { 107 selectOneChoiceTag.setValidator(validator); 108 } 109 if (converter != null) { 110 selectOneChoiceTag.setConverter(converter); 111 } 112 if (binding != null) { 113 selectOneChoiceTag.setBinding(binding); 114 } 115 if (onchange != null) { 116 selectOneChoiceTag.setOnchange(onchange); 117 } 118 if (disabled != null) { 119 selectOneChoiceTag.setDisabled(disabled); 120 } 121 if (markup != null) { 122 selectOneChoiceTag.setMarkup(markup); 123 } 124 if (inline != null) { 125 selectOneChoiceTag.setInline(inline); 126 } 127 if (focus != null) { 128 selectOneChoiceTag.setFocus(focus); 129 } 130 if (id != null) { 131 selectOneChoiceTag.setId(id); 132 } 133 if (readonly != null) { 134 selectOneChoiceTag.setReadonly(readonly); 135 } 136 if (required != null) { 137 selectOneChoiceTag.setRequired(required); 138 } 139 if (tabIndex != null) { 140 selectOneChoiceTag.setTabIndex(tabIndex); 141 } 142 selectOneChoiceTag.setParent(labelTag); 143 selectOneChoiceTag.doStartTag(); 144 145 return super.doStartTag(); 146 } 147 148 @Override 149 public int doEndTag() throws JspException { 150 selectOneChoiceTag.doEndTag(); 151 labelTag.doEndTag(); 152 return super.doEndTag(); 153 } 154 155 @Override 156 public void release() { 157 super.release(); 158 binding = null; 159 onchange = null; 160 disabled = null; 161 inline = null; 162 label = null; 163 labelWidth = null; 164 converter = null; 165 validator = null; 166 readonly = null; 167 rendered = null; 168 required = null; 169 tip = null; 170 value = null; 171 valueChangeListener = null; 172 tabIndex = null; 173 selectOneChoiceTag = null; 174 labelTag = null; 175 focus = null; 176 markup = null; 177 } 178 179 public void setRequired(String required) { 180 this.required = required; 181 } 182 183 public void setValue(String value) { 184 this.value = value; 185 } 186 187 public void setValueChangeListener(String valueChangeListener) { 188 this.valueChangeListener = valueChangeListener; 189 } 190 191 public void setValidator(String validator) { 192 this.validator = validator; 193 } 194 195 public void setDisabled(String disabled) { 196 this.disabled = disabled; 197 } 198 199 public void setReadonly(String readonly) { 200 this.readonly = readonly; 201 } 202 203 public void setOnchange(String onchange) { 204 this.onchange = onchange; 205 } 206 207 public void setConverter(String converter) { 208 this.converter = converter; 209 } 210 211 public void setInline(String inline) { 212 this.inline = inline; 213 } 214 215 public void setLabel(String label) { 216 this.label = label; 217 } 218 219 public void setRendered(String rendered) { 220 this.rendered = rendered; 221 } 222 223 public void setBinding(String binding) { 224 this.binding = binding; 225 } 226 227 public void setTip(String tip) { 228 this.tip = tip; 229 } 230 231 public void setLabelWidth(String labelWidth) { 232 this.labelWidth = labelWidth; 233 } 234 235 public void setTabIndex(String tabIndex) { 236 this.tabIndex = tabIndex; 237 } 238 239 public void setFocus(String focus) { 240 this.focus = focus; 241 } 242 243 public void setMarkup(String markup) { 244 this.markup = markup; 245 } 246 }