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.SelectOneListboxTag; 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.HasDeprecatedHeight; 026 import org.apache.myfaces.tobago.taglib.decl.HasId; 027 import org.apache.myfaces.tobago.taglib.decl.HasLabel; 028 import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth; 029 import org.apache.myfaces.tobago.taglib.decl.HasMarkup; 030 import org.apache.myfaces.tobago.taglib.decl.HasOnchange; 031 import org.apache.myfaces.tobago.taglib.decl.HasTabIndex; 032 import org.apache.myfaces.tobago.taglib.decl.HasTip; 033 import org.apache.myfaces.tobago.taglib.decl.HasValidator; 034 import org.apache.myfaces.tobago.taglib.decl.HasValue; 035 import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener; 036 import org.apache.myfaces.tobago.taglib.decl.IsDisabled; 037 import org.apache.myfaces.tobago.taglib.decl.IsFocus; 038 import org.apache.myfaces.tobago.taglib.decl.IsReadonly; 039 import org.apache.myfaces.tobago.taglib.decl.IsRendered; 040 import org.apache.myfaces.tobago.taglib.decl.IsRequired; 041 import org.apache.myfaces.tobago.util.Deprecation; 042 043 import javax.servlet.jsp.JspException; 044 import javax.servlet.jsp.tagext.BodyTagSupport; 045 046 /** 047 * Render a single selection option listbox. 048 */ 049 @Tag(name = "selectOneListbox") 050 @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.SelectOneListboxTag") 051 public class SelectOneListboxExtensionTag 052 extends BodyTagSupport implements HasId, HasValue, HasValueChangeListener, IsDisabled, 053 HasLabel, HasLabelWidth, IsReadonly, HasOnchange, IsRendered, HasMarkup, 054 HasBinding, HasDeprecatedHeight, IsFocus, HasTip, IsRequired, HasConverter, HasValidator, HasTabIndex { 055 private String required; 056 private String value; 057 private String valueChangeListener; 058 private String disabled; 059 private String readonly; 060 private String onchange; 061 private String inline; 062 private String label; 063 private String rendered; 064 private String binding; 065 private String tip; 066 private String height; 067 private String converter; 068 private String validator; 069 private String labelWidth; 070 private String tabIndex; 071 private String focus; 072 private String markup; 073 074 private LabelExtensionTag labelTag; 075 private SelectOneListboxTag selectOneListboxTag; 076 077 @Override 078 public int doStartTag() throws JspException { 079 080 labelTag = new LabelExtensionTag(); 081 labelTag.setPageContext(pageContext); 082 labelTag.setRows("*"); 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 selectOneListboxTag = new SelectOneListboxTag(); 102 selectOneListboxTag.setPageContext(pageContext); 103 if (value != null) { 104 selectOneListboxTag.setValue(value); 105 } 106 if (valueChangeListener != null) { 107 selectOneListboxTag.setValueChangeListener(valueChangeListener); 108 } 109 if (binding != null) { 110 selectOneListboxTag.setBinding(binding); 111 } 112 if (onchange != null) { 113 selectOneListboxTag.setOnchange(onchange); 114 } 115 if (validator != null) { 116 selectOneListboxTag.setValidator(validator); 117 } 118 if (converter != null) { 119 selectOneListboxTag.setConverter(converter); 120 } 121 if (disabled != null) { 122 selectOneListboxTag.setDisabled(disabled); 123 } 124 if (inline != null) { 125 selectOneListboxTag.setInline(inline); 126 } 127 if (focus != null) { 128 selectOneListboxTag.setFocus(focus); 129 } 130 if (id != null) { 131 selectOneListboxTag.setId(id); 132 } 133 if (height != null) { 134 selectOneListboxTag.setHeight(height); 135 } 136 if (readonly != null) { 137 selectOneListboxTag.setReadonly(readonly); 138 } 139 if (required != null) { 140 selectOneListboxTag.setRequired(required); 141 } 142 if (tabIndex != null) { 143 selectOneListboxTag.setTabIndex(tabIndex); 144 } 145 if (markup != null) { 146 selectOneListboxTag.setMarkup(markup); 147 } 148 selectOneListboxTag.setParent(labelTag); 149 selectOneListboxTag.doStartTag(); 150 151 return super.doStartTag(); 152 } 153 154 @Override 155 public int doEndTag() throws JspException { 156 selectOneListboxTag.doEndTag(); 157 labelTag.doEndTag(); 158 return super.doEndTag(); 159 } 160 161 @Override 162 public void release() { 163 super.release(); 164 binding = null; 165 onchange = null; 166 disabled = null; 167 inline = null; 168 labelWidth = null; 169 label = null; 170 height = null; 171 readonly = null; 172 rendered = null; 173 converter = null; 174 validator = null; 175 required = null; 176 tip = null; 177 value = null; 178 valueChangeListener = null; 179 tabIndex = null; 180 selectOneListboxTag = null; 181 labelTag = null; 182 focus = null; 183 markup = null; 184 } 185 186 public void setRequired(String required) { 187 this.required = required; 188 } 189 190 public void setValue(String value) { 191 this.value = value; 192 } 193 194 public void setValueChangeListener(String valueChangeListener) { 195 this.valueChangeListener = valueChangeListener; 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 setInline(String inline) { 211 this.inline = inline; 212 } 213 214 public void setLabel(String label) { 215 this.label = label; 216 } 217 218 public void setHeight(String height) { 219 if (Deprecation.LOG.isWarnEnabled()) { 220 Deprecation.LOG.warn("Attribute 'height' is deprecated, " 221 + "and will removed soon! Please use a layout manager instead."); 222 } 223 this.height = height; 224 } 225 226 public void setValidator(String validator) { 227 this.validator = validator; 228 } 229 230 public void setConverter(String converter) { 231 this.converter = converter; 232 } 233 234 public void setRendered(String rendered) { 235 this.rendered = rendered; 236 } 237 238 public void setBinding(String binding) { 239 this.binding = binding; 240 } 241 242 public void setTip(String tip) { 243 this.tip = tip; 244 } 245 246 public void setLabelWidth(String labelWidth) { 247 this.labelWidth = labelWidth; 248 } 249 250 public void setTabIndex(String tabIndex) { 251 this.tabIndex = tabIndex; 252 } 253 254 public void setFocus(String focus) { 255 this.focus = focus; 256 } 257 258 public void setMarkup(String markup) { 259 this.markup = markup; 260 } 261 }