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