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