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