View Javadoc

1   package org.apache.myfaces.tobago.taglib.extension12;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one or more
5    * contributor license agreements.  See the NOTICE file distributed with
6    * this work for additional information regarding copyright ownership.
7    * The ASF licenses this file to You under the Apache License, Version 2.0
8    * (the "License"); you may not use this file except in compliance with
9    * the License.  You may obtain a copy of the License at
10   *
11   *      http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
21  import org.apache.myfaces.tobago.apt.annotation.Tag;
22  import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
23  import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
24  import org.apache.myfaces.tobago.apt.annotation.DynamicExpression;
25  import org.apache.myfaces.tobago.internal.taglib.InTag;
26  
27  import javax.servlet.jsp.JspException;
28  
29  /**
30   * Renders a text input field with a label.
31   * <br />
32   * Short syntax of:
33   * <p/>
34   * <pre>
35   * &lt;tc:panel>
36   *   &lt;f:facet name="layout">
37   *     &lt;tc:gridLayout columns="fixed;*"/>
38   *   &lt;/f:facet>
39   *   &lt;tc:label value="#{label}" for="@auto"/>
40   *   &lt;tc:in value="#{value}">
41   *     ...
42   *   &lt;/tc:in>
43   * &lt;/tc:panel>
44   * </pre>
45   */
46  
47  @Tag(name = "in")
48  @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.internal.taglib.InTag")
49  public class InExtensionTag extends TobagoExtensionBodyTagSupport {
50  
51    private javax.el.ValueExpression binding;
52    private javax.el.ValueExpression converter;
53    private javax.el.MethodExpression validator;
54    private javax.el.ValueExpression disabled;
55    private javax.el.ValueExpression focus;
56    private javax.el.ValueExpression label;
57    private javax.el.ValueExpression password;
58    private javax.el.ValueExpression readonly;
59    private javax.el.ValueExpression rendered;
60    private javax.el.ValueExpression required;
61    private javax.el.ValueExpression tip;
62    private javax.el.ValueExpression value;
63    private javax.el.MethodExpression valueChangeListener;
64    private javax.el.ValueExpression onchange;
65    private javax.el.MethodExpression suggestMethod;
66    private javax.el.ValueExpression markup;
67    private javax.el.ValueExpression labelWidth;
68    private javax.el.ValueExpression tabIndex;
69    private javax.el.ValueExpression validatorMessage;
70    private javax.el.ValueExpression converterMessage;
71    private javax.el.ValueExpression requiredMessage;
72  
73    private LabelExtensionTag labelTag;
74    private InTag inTag;
75  
76    @Override
77    public int doStartTag() throws JspException {
78  
79      labelTag = new LabelExtensionTag();
80      labelTag.setPageContext(pageContext);
81      if (label != null) {
82        labelTag.setValue(label);
83      }
84      if (tip != null) {
85        labelTag.setTip(tip);
86      }
87      if (rendered != null) {
88        labelTag.setRendered(rendered);
89      }
90      if (labelWidth != null) {
91        labelTag.setColumns(createStringValueExpression(labelWidth.getExpressionString() + ";*"));
92      }
93      if (markup != null) {
94        labelTag.setMarkup(markup);
95      }
96      labelTag.setParent(getParent());
97      labelTag.doStartTag();
98  
99      inTag = new InTag();
100     inTag.setPageContext(pageContext);
101     if (value != null) {
102       inTag.setValue(value);
103     }
104     if (valueChangeListener != null) {
105       inTag.setValueChangeListener(valueChangeListener);
106     }
107     if (binding != null) {
108       inTag.setBinding(binding);
109     }
110     if (converter != null) {
111       inTag.setConverter(converter);
112     }
113     if (validator != null) {
114       inTag.setValidator(validator);
115     }
116     if (onchange != null) {
117       inTag.setOnchange(onchange);
118     }
119     if (suggestMethod != null) {
120       inTag.setSuggestMethod(suggestMethod);
121     }
122     if (disabled != null) {
123       inTag.setDisabled(disabled);
124     }
125     if (focus != null) {
126       inTag.setFocus(focus);
127     }
128     if (id != null) {
129       inTag.setId(id);
130     }
131     if (password != null) {
132       inTag.setPassword(password);
133     }
134     if (readonly != null) {
135       inTag.setReadonly(readonly);
136     }
137     if (required != null) {
138       inTag.setRequired(required);
139     }
140     if (markup != null) {
141       inTag.setMarkup(markup);
142     }
143     if (tabIndex != null) {
144       inTag.setTabIndex(tabIndex);
145     }
146     if (validatorMessage != null) {
147       inTag.setValidatorMessage(validatorMessage);
148     }
149     if (converterMessage != null) {
150       inTag.setConverterMessage(converterMessage);
151     }
152     if (requiredMessage != null) {
153       inTag.setRequiredMessage(requiredMessage);
154     }
155     inTag.setParent(labelTag);
156     inTag.doStartTag();
157 
158     return super.doStartTag();
159   }
160 
161   @Override
162   public int doEndTag() throws JspException {
163     inTag.doEndTag();
164     labelTag.doEndTag();
165     return super.doEndTag();
166   }
167 
168   @Override
169   public void release() {
170     super.release();
171     binding = null;
172     converter = null;
173     validator = null;
174     disabled = null;
175     labelWidth = null;
176     focus = null;
177     label = null;
178     password = null;
179     readonly = null;
180     rendered = null;
181     required = null;
182     tip = null;
183     value = null;
184     valueChangeListener = null;
185     onchange = null;
186     suggestMethod = null;
187     markup = null;
188     tabIndex = null;
189     inTag = null;
190     labelTag = null;
191     validatorMessage = null;
192     converterMessage = null;
193     requiredMessage = null;
194   }
195 
196   /**
197    * Indicate markup of this component.
198    * Possible value is 'none'. But this can be overridden in the theme.
199    */
200   @TagAttribute
201   @UIComponentTagAttribute(defaultValue = "none", type = "java.lang.String[]")
202   public void setMarkup(javax.el.ValueExpression markup) {
203     this.markup = markup;
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_BINDING_REQUIRED,
227           methodSignature = "javax.faces.event.ValueChangeEvent")
228   public void setValueChangeListener(javax.el.MethodExpression valueChangeListener) {
229     this.valueChangeListener = valueChangeListener;
230   }
231 
232   /**
233    * Text value to display as label.
234    * If text contains an underscore the next character is used as accesskey.
235    */
236   @TagAttribute
237   @UIComponentTagAttribute()
238   public void setLabel(javax.el.ValueExpression label) {
239     this.label = label;
240   }
241 
242   /**
243    * Flag indicating this component should recieve the focus.
244    */
245   @TagAttribute
246   @UIComponentTagAttribute(type = "java.lang.Boolean")
247   public void setFocus(javax.el.ValueExpression focus) {
248     this.focus = focus;
249   }
250 
251   /**
252    * The value binding expression linking this
253    * component to a property in a backing bean.
254    */
255   @TagAttribute
256   @UIComponentTagAttribute(type = "javax.faces.component.UIComponent")
257   public void setBinding(javax.el.ValueExpression binding) {
258     this.binding = binding;
259   }
260   /**
261    * Flag indicating whether or not this component should be rendered
262    * (during Render Response Phase), or processed on any subsequent form submit.
263    */
264   @TagAttribute
265   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "true")
266   public void setRendered(javax.el.ValueExpression rendered) {
267     this.rendered = rendered;
268   }
269 
270   /**
271    * An expression that specifies the Converter for this component.
272    * If the value binding expression is a String,
273    * the String is used as an ID to look up a Converter.
274    * If the value binding expression is a Converter,
275    * uses that instance as the converter.
276    * The value can either be a static value (ID case only)
277    * or an EL expression.
278    */
279   @TagAttribute
280   @UIComponentTagAttribute(type = "javax.faces.convert.Converter",
281       expression = DynamicExpression.VALUE_BINDING)
282   public void setConverter(javax.el.ValueExpression converter) {
283     this.converter = converter;
284   }
285 
286   /**
287    * Clientside script function to add to this component's onchange handler.
288    */
289   @TagAttribute
290   @UIComponentTagAttribute()
291   public void setOnchange(javax.el.ValueExpression onchange) {
292     this.onchange = onchange;
293   }
294 
295   /**
296    * @param suggestMethod
297    */
298   @TagAttribute
299   @UIComponentTagAttribute(type = {},
300       expression = DynamicExpression.METHOD_BINDING_REQUIRED,
301       methodSignature = "java.lang.String")
302   public void setSuggestMethod(javax.el.MethodExpression suggestMethod) {
303     this.suggestMethod = suggestMethod;
304   }
305 
306   /**
307    * A method binding EL expression,
308    * accepting FacesContext, UIComponent,
309    * and Object parameters, and returning void, that validates
310    * the component's local value.
311    */
312   @TagAttribute
313   @UIComponentTagAttribute(type = {},
314       expression = DynamicExpression.METHOD_BINDING,
315       methodSignature = { "javax.faces.context.FacesContext", "javax.faces.component.UIComponent", "java.lang.Object" })
316   public void setValidator(javax.el.MethodExpression validator) {
317     this.validator = validator;
318   }
319 
320   /**
321    * Flag indicating whether or not this component should be rendered as
322    * password field , so you will not see the typed charakters.
323    */
324   @TagAttribute
325   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "false")
326   public void setPassword(javax.el.ValueExpression password) {
327     this.password = password;
328   }
329 
330   /**
331    * Flag indicating that this component will prohibit changes by the user.
332    */
333   @TagAttribute
334   @UIComponentTagAttribute(type = "java.lang.Boolean")
335   public void setReadonly(javax.el.ValueExpression readonly) {
336     this.readonly = readonly;
337   }
338 
339   /**
340    * Flag indicating that this element is disabled.
341    */
342   @TagAttribute()
343   @UIComponentTagAttribute(type = "java.lang.Boolean", defaultValue = "false")
344   public void setDisabled(javax.el.ValueExpression disabled) {
345     this.disabled = disabled;
346   }
347 
348   /**
349    * Flag indicating that a value is required.
350    * If the value is an empty string a
351    * ValidationError occurs and a Error Message is rendered.
352    */
353   @TagAttribute
354   @UIComponentTagAttribute(type = "java.lang.Boolean")
355   public void setRequired(javax.el.ValueExpression required) {
356     this.required = required;
357   }
358 
359   /**
360    * Text value to display as tooltip.
361    */
362   @TagAttribute
363   @UIComponentTagAttribute()
364   public void setTip(javax.el.ValueExpression tip) {
365     this.tip = tip;
366   }
367 
368    /**
369    * The width for the label component. Default: 'fixed'.
370    * This value is used in the gridLayouts columns attribute.
371    * See gridLayout tag for valid values.
372    */
373   @TagAttribute
374   @UIComponentTagAttribute()
375   public void setLabelWidth(javax.el.ValueExpression labelWidth) {
376     this.labelWidth = labelWidth;
377   }
378 
379   @TagAttribute
380   @UIComponentTagAttribute(type = "java.lang.Integer")
381   public void setTabIndex(javax.el.ValueExpression tabIndex) {
382     this.tabIndex = tabIndex;
383   }
384 
385   /**
386    * An expression that specifies the validator message
387    */
388   @TagAttribute
389   @UIComponentTagAttribute()
390   public void setValidatorMessage(javax.el.ValueExpression validatorMessage) {
391     this.validatorMessage = validatorMessage;
392   }
393 
394   /**
395    * An expression that specifies the converter message
396    */
397   @TagAttribute
398   @UIComponentTagAttribute()
399   public void setConverterMessage(javax.el.ValueExpression converterMessage) {
400     this.converterMessage = converterMessage;
401   }
402 
403   /**
404    * An expression that specifies the required message
405    */
406   @TagAttribute
407   @UIComponentTagAttribute()
408   public void setRequiredMessage(javax.el.ValueExpression requiredMessage) {
409     this.requiredMessage = requiredMessage;
410   }
411 
412 }