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.el.MethodExpression;
30  import javax.el.ValueExpression;
31  import javax.servlet.jsp.JspException;
32  
33  /**
34   * Renders a multi selection option listbox with a label.
35   */
36  @Tag(name = "selectManyListbox")
37  @ExtensionTag(
38      baseClassName = "org.apache.myfaces.tobago.internal.taglib.SelectManyListboxTag",
39      faceletHandler = "org.apache.myfaces.tobago.facelets.extension.SelectManyListboxExtensionHandler")
40  public class SelectManyListboxExtensionTag extends TobagoExtensionBodyTagSupport {
41  
42    private ValueExpression required;
43    private ValueExpression value;
44    private MethodExpression valueChangeListener;
45    private ValueExpression disabled;
46    private ValueExpression readonly;
47    private ValueExpression onchange;
48    private ValueExpression label;
49    private ValueExpression accessKey;
50    private ValueExpression rendered;
51    private ValueExpression binding;
52    private ValueExpression tip;
53    private ValueExpression converter;
54    private MethodExpression validator;
55    private ValueExpression labelWidth;
56    private ValueExpression markup;
57    private ValueExpression tabIndex;
58    private ValueExpression focus;
59    private ValueExpression validatorMessage;
60    private ValueExpression converterMessage;
61    private ValueExpression requiredMessage;
62    private String fieldId;
63  
64    private LabelExtensionTag labelTag;
65    private SelectManyListboxTag selectManyListboxTag;
66  
67    @Override
68    public int doStartTag() throws JspException {
69  
70      labelTag = new LabelExtensionTag();
71      labelTag.setPageContext(pageContext);
72      labelTag.setRows("*");
73      if (id != null) {
74        labelTag.setId(id);
75      }
76      if (label != null) {
77        labelTag.setValue(label);
78      }
79      if (accessKey != null) {
80        labelTag.setAccessKey(accessKey);
81      }
82      if (tip != null) {
83        labelTag.setTip(tip);
84      }
85      if (rendered != null) {
86        labelTag.setRendered(rendered);
87      }
88      if (labelWidth != null) {
89        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
90      }
91      if (markup != null) {
92        labelTag.setMarkup(markup);
93      }
94      labelTag.setParent(getParent());
95      labelTag.setJspId(nextJspId());
96      labelTag.doStartTag();
97  
98      selectManyListboxTag = new SelectManyListboxTag();
99      selectManyListboxTag.setPageContext(pageContext);
100     if (value != null) {
101       selectManyListboxTag.setValue(value);
102     }
103     if (valueChangeListener != null) {
104       selectManyListboxTag.setValueChangeListener(valueChangeListener);
105     }
106     if (binding != null) {
107       selectManyListboxTag.setBinding(binding);
108     }
109     if (onchange != null) {
110       selectManyListboxTag.setOnchange(onchange);
111     }
112     if (validator != null) {
113       selectManyListboxTag.setValidator(validator);
114     }
115     if (converter != null) {
116       selectManyListboxTag.setConverter(converter);
117     }
118     if (disabled != null) {
119       selectManyListboxTag.setDisabled(disabled);
120     }
121     if (focus != null) {
122       selectManyListboxTag.setFocus(focus);
123     }
124     if (fieldId != null) {
125       selectManyListboxTag.setId(fieldId);
126     }
127     if (label != null) {
128       selectManyListboxTag.setLabel(label);
129     }
130     if (readonly != null) {
131       selectManyListboxTag.setReadonly(readonly);
132     }
133     if (required != null) {
134       selectManyListboxTag.setRequired(required);
135     }
136     if (markup != null) {
137       selectManyListboxTag.setMarkup(markup);
138     }
139     if (tabIndex != null) {
140       selectManyListboxTag.setTabIndex(tabIndex);
141     }
142     if (validatorMessage != null) {
143       selectManyListboxTag.setValidatorMessage(validatorMessage);
144     }
145     if (converterMessage != null) {
146       selectManyListboxTag.setConverterMessage(converterMessage);
147     }
148     if (requiredMessage != null) {
149       selectManyListboxTag.setRequiredMessage(requiredMessage);
150     }
151     selectManyListboxTag.setParent(labelTag);
152     selectManyListboxTag.setJspId(nextJspId());
153     selectManyListboxTag.doStartTag();
154 
155     return super.doStartTag();
156   }
157 
158   @Override
159   public int doEndTag() throws JspException {
160     selectManyListboxTag.doEndTag();
161     labelTag.doEndTag();
162     return super.doEndTag();
163   }
164 
165   @Override
166   public void release() {
167     super.release();
168     binding = null;
169     onchange = null;
170     disabled = null;
171     label = null;
172     accessKey = null;
173     labelWidth = null;
174     readonly = null;
175     rendered = null;
176     converter = null;
177     validator = null;
178     required = null;
179     tip = null;
180     value = null;
181     valueChangeListener = null;
182     markup = null;
183     tabIndex = null;
184     selectManyListboxTag = null;
185     labelTag = null;
186     focus = null;
187     validatorMessage = null;
188     converterMessage = null;
189     requiredMessage = null;
190     fieldId = null;
191   }
192 
193   /**
194    * Flag indicating that a value is required.
195    * If the value is an empty string a
196    * ValidationError occurs and a Error Message is rendered.
197    */
198   @TagAttribute
199   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
200   public void setRequired(final ValueExpression required) {
201     this.required = required;
202   }
203 
204   /**
205    * The current value of this component.
206    */
207   @TagAttribute
208   @UIComponentTagAttribute(type = "java.lang.Object")
209   public void setValue(final ValueExpression value) {
210     this.value = value;
211   }
212 
213   /**
214    * MethodBinding representing a value change listener method
215    * that will be notified when a new value has been set for this input component.
216    * The expression must evaluate to a public method that takes a ValueChangeEvent
217    * parameter, with a return type of void.
218    *
219    * @param valueChangeListener
220    */
221   @TagAttribute
222   @UIComponentTagAttribute(
223           type = {},
224           expression = DynamicExpression.METHOD_EXPRESSION_REQUIRED,
225           methodSignature = "javax.faces.event.ValueChangeEvent")
226   public void setValueChangeListener(final MethodExpression valueChangeListener) {
227     this.valueChangeListener = valueChangeListener;
228   }
229 
230   /**
231    * Flag indicating that this element is disabled.
232    */
233   @TagAttribute()
234   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
235   public void setDisabled(final ValueExpression disabled) {
236     this.disabled = disabled;
237   }
238 
239   /**
240    * Flag indicating that this component will prohibit changes by the user.
241    */
242   @TagAttribute
243   @UIComponentTagAttribute(type = "boolean", defaultValue = "false")
244   public void setReadonly(final ValueExpression readonly) {
245     this.readonly = readonly;
246   }
247 
248   /**
249    * Clientside script function to add to this component's onchange handler.
250    */
251   @TagAttribute
252   @UIComponentTagAttribute()
253   public void setOnchange(final ValueExpression onchange) {
254     this.onchange = onchange;
255   }
256 
257   /**
258    * Text value to display as label.
259    * If text contains an underscore the next character is used as accesskey.
260    */
261   @TagAttribute
262   @UIComponentTagAttribute()
263   public void setLabel(final ValueExpression label) {
264     this.label = label;
265   }
266 
267   /**
268    * The accessKey of this component.
269    */
270   @TagAttribute
271   @UIComponentTagAttribute(type = "java.lang.Character")
272   public void setAccessKey(final javax.el.ValueExpression accessKey) {
273     this.accessKey = accessKey;
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(final 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(final 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(final 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(final 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(final 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(final 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(final ValueExpression markup) {
353     this.markup = markup;
354   }
355 
356   @TagAttribute
357   @UIComponentTagAttribute(type = "java.lang.Integer")
358   public void setTabIndex(final 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(final 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(final 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(final 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(final 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(final 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(final String id) {
417     super.setId(id);
418   }
419 }