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