View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.internal.taglib.extension;
21  
22  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
23  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
24  import org.apache.myfaces.tobago.apt.annotation.Tag;
25  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
26  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
27  import org.apache.myfaces.tobago.internal.taglib.SelectManyListboxTag;
28  
29  import javax.servlet.jsp.JspException;
30  
31  /**
32   * Renders a multi selection option listbox with a label.
33   */
34  @Tag(name = "selectManyListbox")
35  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.SelectManyListboxTag")
36  public class SelectManyListboxExtensionTag extends TobagoExtensionBodyTagSupport {
37  
38    private javax.el.ValueExpression required;
39    private javax.el.ValueExpression value;
40    private javax.el.MethodExpression valueChangeListener;
41    private javax.el.ValueExpression disabled;
42    private javax.el.ValueExpression readonly;
43    private javax.el.ValueExpression onchange;
44    private javax.el.ValueExpression inline;
45    private javax.el.ValueExpression label;
46    private javax.el.ValueExpression rendered;
47    private javax.el.ValueExpression binding;
48    private javax.el.ValueExpression tip;
49    private javax.el.ValueExpression converter;
50    private javax.el.MethodExpression validator;
51    private javax.el.ValueExpression labelWidth;
52    private javax.el.ValueExpression markup;
53    private javax.el.ValueExpression tabIndex;
54    private javax.el.ValueExpression focus;
55    private javax.el.ValueExpression validatorMessage;
56    private javax.el.ValueExpression converterMessage;
57    private javax.el.ValueExpression requiredMessage;
58    private String fieldId;
59  
60    private LabelExtensionTag labelTag;
61    private SelectManyListboxTag selectManyListboxTag;
62  
63    @Override
64    public int doStartTag() throws JspException {
65  
66      labelTag = new LabelExtensionTag();
67      labelTag.setPageContext(pageContext);
68      labelTag.setRows("*");
69      if (id != null) {
70        labelTag.setId(id);
71      }
72      if (label != null) {
73        labelTag.setValue(label);
74      }
75      if (tip != null) {
76        labelTag.setTip(tip);
77      }
78      if (rendered != null) {
79        labelTag.setRendered(rendered);
80      }
81      if (labelWidth != null) {
82        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
83      }
84      if (markup != null) {
85        labelTag.setMarkup(markup);
86      }
87      labelTag.setParent(getParent());
88      labelTag.setJspId(nextJspId());
89      labelTag.doStartTag();
90  
91      selectManyListboxTag = new SelectManyListboxTag();
92      selectManyListboxTag.setPageContext(pageContext);
93      if (value != null) {
94        selectManyListboxTag.setValue(value);
95      }
96      if (valueChangeListener != null) {
97        selectManyListboxTag.setValueChangeListener(valueChangeListener);
98      }
99      if (binding != null) {
100       selectManyListboxTag.setBinding(binding);
101     }
102     if (onchange != null) {
103       selectManyListboxTag.setOnchange(onchange);
104     }
105     if (validator != null) {
106       selectManyListboxTag.setValidator(validator);
107     }
108     if (converter != null) {
109       selectManyListboxTag.setConverter(converter);
110     }
111     if (disabled != null) {
112       selectManyListboxTag.setDisabled(disabled);
113     }
114     if (inline != null) {
115       selectManyListboxTag.setInline(inline);
116     }
117     if (focus != null) {
118       selectManyListboxTag.setFocus(focus);
119     }
120     if (fieldId != null) {
121       selectManyListboxTag.setId(fieldId);
122     }
123     if (label != null) {
124       selectManyListboxTag.setLabel(label);
125     }
126     if (readonly != null) {
127       selectManyListboxTag.setReadonly(readonly);
128     }
129     if (required != null) {
130       selectManyListboxTag.setRequired(required);
131     }
132     if (markup != null) {
133       selectManyListboxTag.setMarkup(markup);
134     }
135     if (tabIndex != null) {
136       selectManyListboxTag.setTabIndex(tabIndex);
137     }
138     if (validatorMessage != null) {
139       selectManyListboxTag.setValidatorMessage(validatorMessage);
140     }
141     if (converterMessage != null) {
142       selectManyListboxTag.setConverterMessage(converterMessage);
143     }
144     if (requiredMessage != null) {
145       selectManyListboxTag.setRequiredMessage(requiredMessage);
146     }
147     selectManyListboxTag.setParent(labelTag);
148     selectManyListboxTag.setJspId(nextJspId());
149     selectManyListboxTag.doStartTag();
150 
151     return super.doStartTag();
152   }
153 
154   @Override
155   public int doEndTag() throws JspException {
156     selectManyListboxTag.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     label = null;
169     labelWidth = null;
170     readonly = null;
171     rendered = null;
172     converter = null;
173     validator = null;
174     required = null;
175     tip = null;
176     value = null;
177     valueChangeListener = null;
178     markup = null;
179     tabIndex = null;
180     selectManyListboxTag = null;
181     labelTag = null;
182     focus = null;
183     validatorMessage = null;
184     converterMessage = null;
185     requiredMessage = null;
186     fieldId = null;
187   }
188 
189   /**
190    * Flag indicating that a value is required.
191    * If the value is an empty string a
192    * ValidationError occurs and a Error Message is rendered.
193    */
194   @TagAttribute
195   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
196   public void setRequired(javax.el.ValueExpression required) {
197     this.required = required;
198   }
199 
200   /**
201    * The current value of this component.
202    */
203   @TagAttribute
204   @UIComponentTagAttribute(type = "java.lang.Object")
205   public void setValue(javax.el.ValueExpression value) {
206     this.value = value;
207   }
208 
209   /**
210    * MethodBinding representing a value change listener method
211    * that will be notified when a new value has been set for this input component.
212    * The expression must evaluate to a public method that takes a ValueChangeEvent
213    * parameter, with a return type of void.
214    *
215    * @param valueChangeListener
216    */
217   @TagAttribute
218   @UIComponentTagAttribute(
219           type = {},
220           expression = DynamicExpression.METHOD_EXPRESSION_REQUIRED,
221           methodSignature = "javax.faces.event.ValueChangeEvent")
222   public void setValueChangeListener(javax.el.MethodExpression valueChangeListener) {
223     this.valueChangeListener = valueChangeListener;
224   }
225 
226   /**
227    * Flag indicating that this element is disabled.
228    */
229   @TagAttribute()
230   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
231   public void setDisabled(javax.el.ValueExpression disabled) {
232     this.disabled = disabled;
233   }
234 
235   /**
236    * Flag indicating that this component will prohibit changes by the user.
237    */
238   @TagAttribute
239   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
240   public void setReadonly(javax.el.ValueExpression readonly) {
241     this.readonly = readonly;
242   }
243 
244   /**
245    * Clientside script function to add to this component's onchange handler.
246    */
247   @TagAttribute
248   @UIComponentTagAttribute()
249   public void setOnchange(javax.el.ValueExpression onchange) {
250     this.onchange = onchange;
251   }
252 
253   /**
254    * Flag indicating this component should rendered as an inline element.
255    * @deprecated This should be handled by e.g. a flow layout manager (since 1.5.0)
256    */
257   @TagAttribute
258   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
259   @Deprecated
260   public void setInline(javax.el.ValueExpression inline) {
261     this.inline = inline;
262   }
263 
264   /**
265    * Text value to display as label.
266    * If text contains an underscore the next character is used as accesskey.
267    */
268   @TagAttribute
269   @UIComponentTagAttribute()
270   public void setLabel(javax.el.ValueExpression label) {
271     this.label = label;
272   }
273 
274   /**
275    * A method binding EL expression,
276    * accepting FacesContext, UIComponent,
277    * and Object parameters, and returning void, that validates
278    * the component's local value.
279    */
280   @TagAttribute
281   @UIComponentTagAttribute(type = {},
282       expression = DynamicExpression.METHOD_EXPRESSION,
283       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
284   public void setValidator(javax.el.MethodExpression validator) {
285     this.validator = validator;
286   }
287 
288   /**
289    * An expression that specifies the Converter for this component.
290    * If the value binding expression is a String,
291    * the String is used as an ID to look up a Converter.
292    * If the value binding expression is a Converter,
293    * uses that instance as the converter.
294    * The value can either be a static value (ID case only)
295    * or an EL expression.
296    */
297   @TagAttribute
298   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
299       expression = DynamicExpression.VALUE_EXPRESSION)
300   public void setConverter(javax.el.ValueExpression converter) {
301     this.converter = converter;
302   }
303 
304   /**
305    * Flag indicating whether or not this component should be rendered
306    * (during Render Response Phase), or processed on any subsequent form submit.
307    */
308   @TagAttribute
309   @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
310   public void setRendered(javax.el.ValueExpression rendered) {
311     this.rendered = rendered;
312   }
313 
314   /**
315    * The value binding expression linking this
316    * component to a property in a backing bean.
317    */
318   @TagAttribute
319   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
320   public void setBinding(javax.el.ValueExpression binding) {
321     this.binding = binding;
322   }
323 
324   /**
325    * Text value to display as tooltip.
326    */
327   @TagAttribute
328   @UIComponentTagAttribute()
329   public void setTip(javax.el.ValueExpression tip) {
330     this.tip = tip;
331   }
332 
333   /**
334    * The width for the label component. Default: 'auto'.
335    * This value is used in the gridLayouts columns attribute.
336    * See gridLayout tag for valid values.
337    */
338   @TagAttribute
339   @UIComponentTagAttribute()
340   public void setLabelWidth(javax.el.ValueExpression labelWidth) {
341     this.labelWidth = labelWidth;
342   }
343 
344   /**
345    * Indicate markup of this component.
346    * Possible value is 'none'. But this can be overridden in the theme.
347    */
348   @TagAttribute
349   @UIComponentTagAttribute(defaultValue = "none", type = "java.lang.String[]")
350   public void setMarkup(javax.el.ValueExpression markup) {
351     this.markup = markup;
352   }
353 
354   @TagAttribute
355   @UIComponentTagAttribute(type = "java.lang.Integer")
356   public void setTabIndex(javax.el.ValueExpression tabIndex) {
357     this.tabIndex = tabIndex;
358   }
359 
360   /**
361    * Flag indicating this component should receive the focus.
362    */
363   @TagAttribute
364   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
365   public void setFocus(javax.el.ValueExpression focus) {
366     this.focus = focus;
367   }
368 
369   /**
370    * An expression that specifies the validator message
371    */
372   @TagAttribute
373   @UIComponentTagAttribute()
374   public void setValidatorMessage(javax.el.ValueExpression validatorMessage) {
375     this.validatorMessage = validatorMessage;
376   }
377 
378   /**
379    * An expression that specifies the converter message
380    */
381   @TagAttribute
382   @UIComponentTagAttribute()
383   public void setConverterMessage(javax.el.ValueExpression converterMessage) {
384     this.converterMessage = converterMessage;
385   }
386 
387   /**
388    * An expression that specifies the required message
389    */
390   @TagAttribute
391   @UIComponentTagAttribute()
392   public void setRequiredMessage(javax.el.ValueExpression requiredMessage) {
393     this.requiredMessage = requiredMessage;
394   }
395   
396   /**
397    * The component identifier for the input field component inside of the container.
398    * This value must be unique within the closest parent component that is a naming container.
399    */
400   @TagAttribute(rtexprvalue = true)
401   @UIComponentTagAttribute
402   public void setFieldId(String fieldId) {
403     this.fieldId = fieldId;
404   }
405 
406   /**
407    * The component identifier for this component.
408    * This value must be unique within the closest parent component that is a naming container.
409    * For tx components the id will be set to the container (e. g. the panel).
410    * To set the id of the input field, you have to use the attribute "fieldId".
411    */
412   @TagAttribute(rtexprvalue = true)
413   @UIComponentTagAttribute
414   public void setId(String id) {
415     super.setId(id);
416   }
417 }