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