View Javadoc

1   package org.apache.myfaces.tobago.taglib.extension;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
21  import org.apache.myfaces.tobago.apt.annotation.Tag;
22  import org.apache.myfaces.tobago.internal.taglib.SelectOneChoiceTag;
23  import org.apache.myfaces.tobago.taglib.decl.HasBinding;
24  import org.apache.myfaces.tobago.taglib.decl.HasConverter;
25  import org.apache.myfaces.tobago.taglib.decl.HasId;
26  import org.apache.myfaces.tobago.taglib.decl.HasLabel;
27  import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth;
28  import org.apache.myfaces.tobago.taglib.decl.HasOnchange;
29  import org.apache.myfaces.tobago.taglib.decl.HasTabIndex;
30  import org.apache.myfaces.tobago.taglib.decl.HasTip;
31  import org.apache.myfaces.tobago.taglib.decl.HasValidator;
32  import org.apache.myfaces.tobago.taglib.decl.HasValue;
33  import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
34  import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
35  import org.apache.myfaces.tobago.taglib.decl.IsFocus;
36  import org.apache.myfaces.tobago.taglib.decl.IsInline;
37  import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
38  import org.apache.myfaces.tobago.taglib.decl.IsRendered;
39  import org.apache.myfaces.tobago.taglib.decl.IsRequired;
40  import org.apache.myfaces.tobago.taglib.decl.HasMarkup;
41  import org.apache.myfaces.tobago.taglib.decl.HasValidatorMessage;
42  import org.apache.myfaces.tobago.taglib.decl.HasRequiredMessage;
43  import org.apache.myfaces.tobago.taglib.decl.HasConverterMessage;
44  
45  import javax.servlet.jsp.JspException;
46  import javax.servlet.jsp.tagext.BodyTagSupport;
47  
48  /**
49   * Render a single selection dropdown list with a label.
50   */
51  
52  @Tag(name = "selectOneChoice")
53  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.SelectOneChoiceTag")
54  public class SelectOneChoiceExtensionTag
55      extends BodyTagSupport
56      implements HasId, HasValue, HasValueChangeListener, IsDisabled,
57      IsReadonly, HasOnchange, IsInline, HasLabel, HasLabelWidth, IsRequired,
58      HasValidatorMessage, HasRequiredMessage, HasConverterMessage,
59      IsRendered, IsFocus, HasBinding, HasTip, HasValidator, HasConverter, HasMarkup, HasTabIndex {
60  
61    private String required;
62    private String value;
63    private String valueChangeListener;
64    private String disabled;
65    private String readonly;
66    private String onchange;
67    private String inline;
68    private String label;
69    private String rendered;
70    private String binding;
71    private String tip;
72    private String validator;
73    private String converter;
74    private String labelWidth;
75    private String tabIndex;
76    private String focus;
77    private String markup;
78    private String validatorMessage;
79    private String converterMessage;
80    private String requiredMessage;
81  
82    private LabelExtensionTag labelTag;
83    private SelectOneChoiceTag selectOneChoiceTag;
84  
85    @Override
86    public int doStartTag() throws JspException {
87  
88      labelTag = new LabelExtensionTag();
89      labelTag.setPageContext(pageContext);
90      if (label != null) {
91        labelTag.setValue(label);
92      }
93      if (tip != null) {
94        labelTag.setTip(tip);
95      }
96      if (rendered != null) {
97        labelTag.setRendered(rendered);
98      }
99      if (labelWidth != null) {
100       labelTag.setColumns(labelWidth + ";*");
101     }
102     if (markup != null) {
103       labelTag.setMarkup(markup);
104     }
105     labelTag.setParent(getParent());
106     labelTag.doStartTag();
107 
108     selectOneChoiceTag = new SelectOneChoiceTag();
109     selectOneChoiceTag.setPageContext(pageContext);
110     if (value != null) {
111       selectOneChoiceTag.setValue(value);
112     }
113     if (valueChangeListener != null) {
114       selectOneChoiceTag.setValueChangeListener(valueChangeListener);
115     }
116     if (validator != null) {
117       selectOneChoiceTag.setValidator(validator);
118     }
119     if (converter != null) {
120       selectOneChoiceTag.setConverter(converter);
121     }
122     if (binding != null) {
123       selectOneChoiceTag.setBinding(binding);
124     }
125     if (onchange != null) {
126       selectOneChoiceTag.setOnchange(onchange);
127     }
128     if (disabled != null) {
129       selectOneChoiceTag.setDisabled(disabled);
130     }
131     if (markup != null) {
132       selectOneChoiceTag.setMarkup(markup);
133     }
134     if (inline != null) {
135       selectOneChoiceTag.setInline(inline);
136     }
137     if (focus != null) {
138       selectOneChoiceTag.setFocus(focus);
139     }
140     if (id != null) {
141       selectOneChoiceTag.setId(id);
142     }
143     if (readonly != null) {
144       selectOneChoiceTag.setReadonly(readonly);
145     }
146     if (required != null) {
147       selectOneChoiceTag.setRequired(required);
148     }
149     if (tabIndex != null) {
150       selectOneChoiceTag.setTabIndex(tabIndex);
151     }
152     if (validatorMessage != null) {
153       selectOneChoiceTag.setValidatorMessage(validatorMessage);
154     }
155     if (converterMessage != null) {
156       selectOneChoiceTag.setConverterMessage(converterMessage);
157     }
158     if (requiredMessage != null) {
159       selectOneChoiceTag.setRequiredMessage(requiredMessage);
160     }
161 
162     selectOneChoiceTag.setParent(labelTag);
163     selectOneChoiceTag.doStartTag();
164 
165     return super.doStartTag();
166   }
167 
168   @Override
169   public int doEndTag() throws JspException {
170     selectOneChoiceTag.doEndTag();
171     labelTag.doEndTag();
172     return super.doEndTag();
173   }
174 
175   @Override
176   public void release() {
177     super.release();
178     binding = null;
179     onchange = null;
180     disabled = null;
181     inline = null;
182     label = null;
183     labelWidth = null;
184     converter = null;
185     validator = null;
186     readonly = null;
187     rendered = null;
188     required = null;
189     tip = null;
190     value = null;
191     valueChangeListener = null;
192     tabIndex = null;
193     selectOneChoiceTag = null;
194     labelTag = null;
195     focus = null;
196     markup = null;
197     validatorMessage = null;
198     converterMessage = null;
199     requiredMessage = null;
200   }
201 
202   public void setRequired(String required) {
203     this.required = required;
204   }
205 
206   public void setValue(String value) {
207     this.value = value;
208   }
209 
210   public void setValueChangeListener(String valueChangeListener) {
211     this.valueChangeListener = valueChangeListener;
212   }
213 
214   public void setValidator(String validator) {
215     this.validator = validator;
216   }
217 
218   public void setDisabled(String disabled) {
219     this.disabled = disabled;
220   }
221 
222   public void setReadonly(String readonly) {
223     this.readonly = readonly;
224   }
225 
226   public void setOnchange(String onchange) {
227     this.onchange = onchange;
228   }
229 
230   public void setConverter(String converter) {
231     this.converter = converter;
232   }
233 
234   public void setInline(String inline) {
235     this.inline = inline;
236   }
237 
238   public void setLabel(String label) {
239     this.label = label;
240   }
241 
242   public void setRendered(String rendered) {
243     this.rendered = rendered;
244   }
245 
246   public void setBinding(String binding) {
247     this.binding = binding;
248   }
249 
250   public void setTip(String tip) {
251     this.tip = tip;
252   }
253 
254   public void setLabelWidth(String labelWidth) {
255     this.labelWidth = labelWidth;
256   }
257 
258   public void setTabIndex(String tabIndex) {
259     this.tabIndex = tabIndex;
260   }
261 
262   public void setFocus(String focus) {
263     this.focus = focus;
264   }
265 
266   public void setMarkup(String markup) {
267     this.markup = markup;
268   }
269 
270   public void setValidatorMessage(String validatorMessage) {
271     this.validatorMessage = validatorMessage;
272   }
273 
274   public void setConverterMessage(String converterMessage) {
275     this.converterMessage = converterMessage;
276   }
277 
278   public void setRequiredMessage(String requiredMessage) {
279     this.requiredMessage = requiredMessage;
280   }
281 }