001    package org.apache.myfaces.tobago.taglib.extension;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one or more
005     * contributor license agreements.  See the NOTICE file distributed with
006     * this work for additional information regarding copyright ownership.
007     * The ASF licenses this file to You under the Apache License, Version 2.0
008     * (the "License"); you may not use this file except in compliance with
009     * the License.  You may obtain a copy of the License at
010     *
011     *      http://www.apache.org/licenses/LICENSE-2.0
012     *
013     * Unless required by applicable law or agreed to in writing, software
014     * distributed under the License is distributed on an "AS IS" BASIS,
015     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016     * See the License for the specific language governing permissions and
017     * limitations under the License.
018     */
019    
020    import org.apache.myfaces.tobago.apt.annotation.Tag;
021    import org.apache.myfaces.tobago.apt.annotation.ExtensionTag;
022    import org.apache.myfaces.tobago.taglib.component.InTag;
023    import org.apache.myfaces.tobago.taglib.decl.HasConverter;
024    import org.apache.myfaces.tobago.taglib.decl.HasIdBindingAndRendered;
025    import org.apache.myfaces.tobago.taglib.decl.HasLabel;
026    import org.apache.myfaces.tobago.taglib.decl.HasTip;
027    import org.apache.myfaces.tobago.taglib.decl.HasValidator;
028    import org.apache.myfaces.tobago.taglib.decl.HasValue;
029    import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
030    import org.apache.myfaces.tobago.taglib.decl.IsFocus;
031    import org.apache.myfaces.tobago.taglib.decl.IsPassword;
032    import org.apache.myfaces.tobago.taglib.decl.IsReadonly;
033    import org.apache.myfaces.tobago.taglib.decl.IsRequired;
034    import org.apache.myfaces.tobago.taglib.decl.HasOnchange;
035    import org.apache.myfaces.tobago.taglib.decl.HasValueChangeListener;
036    import org.apache.myfaces.tobago.taglib.decl.HasSuggestMethod;
037    import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth;
038    import org.apache.myfaces.tobago.taglib.decl.HasMarkup;
039    
040    import javax.servlet.jsp.JspException;
041    import javax.servlet.jsp.tagext.BodyTagSupport;
042    
043    /**
044     * Renders a text input field with a label.
045     * <br>
046     * Short syntax of:
047     *
048     * <pre>
049     * &lt;tc:panel>
050     *   &lt;f:facet name="layout">
051     *     &lt;tc:gridLayout columns="fixed;*"/>
052     *   &lt;/f:facet>
053     *   &lt;tc:label value="#{label}" for="@auto"/>
054     *   &lt;tc:in value="#{value}">
055     *     ...
056     *   &lt;/tc:in>
057     * &lt;/tc:panel>
058     * </pre>
059     */
060    
061    @Tag(name = "in")
062    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.InTag")
063    public class InExtensionTag extends BodyTagSupport
064        implements HasValue, HasValueChangeListener, HasValidator, HasIdBindingAndRendered,
065        HasConverter, IsReadonly, IsDisabled, HasOnchange, HasMarkup,
066        IsRequired, HasTip, HasLabel, HasLabelWidth, IsPassword, IsFocus, HasSuggestMethod {
067    
068      private String binding;
069      private String converter;
070      private String validator;
071      private String disabled;
072      private String focus;
073      private String label;
074      private String password;
075      private String readonly;
076      private String rendered;
077      private String required;
078      private String tip;
079      private String value;
080      private String valueChangeListener;
081      private String onchange;
082      private String suggestMethod;
083      private String markup;
084      private String labelWidth;
085    
086      private LabelExtensionTag labelTag;
087      private InTag inTag;
088    
089      @Override
090      public int doStartTag() throws JspException {
091    
092        labelTag = new LabelExtensionTag();
093        labelTag.setPageContext(pageContext);
094        if (label != null) {
095          labelTag.setValue(label);
096        }
097        if (tip != null) {
098          labelTag.setTip(tip);
099        }
100        if (rendered != null) {
101          labelTag.setRendered(rendered);
102        }
103        if (labelWidth != null) {
104          labelTag.setColumns(labelWidth + ";*");
105        }
106    
107        labelTag.setParent(getParent());
108        labelTag.doStartTag();
109    
110        inTag = new InTag();
111        inTag.setPageContext(pageContext);
112        if (value != null) {
113          inTag.setValue(value);
114        }
115        if (valueChangeListener != null) {
116          inTag.setValueChangeListener(valueChangeListener);
117        }
118        if (binding != null) {
119          inTag.setBinding(binding);
120        }
121        if (converter != null) {
122          inTag.setConverter(converter);
123        }
124        if (validator != null) {
125          inTag.setValidator(validator);
126        }
127         if (onchange != null) {
128          inTag.setOnchange(onchange);
129        }
130        if (suggestMethod != null) {
131         inTag.setSuggestMethod(suggestMethod);
132       }
133        if (disabled != null) {
134          inTag.setDisabled(disabled);
135        }
136        if (focus != null) {
137          inTag.setFocus(focus);
138        }
139        if (id != null) {
140          inTag.setId(id);
141        }
142        if (password != null) {
143          inTag.setPassword(password);
144        }
145        if (readonly != null) {
146          inTag.setReadonly(readonly);
147        }
148        if (required != null) {
149          inTag.setRequired(required);
150        }
151        if (markup != null) {
152          inTag.setMarkup(markup);
153        }
154        inTag.setParent(labelTag);
155        inTag.doStartTag();
156    
157        return super.doStartTag();
158      }
159    
160      @Override
161      public int doEndTag() throws JspException {
162        inTag.doEndTag();
163        labelTag.doEndTag();
164        return super.doEndTag();
165      }
166    
167      @Override
168      public void release() {
169        super.release();
170        binding = null;
171        converter = null;
172        validator = null;
173        disabled = null;
174        labelWidth = null;
175        focus = null;
176        label = null;
177        password = null;
178        readonly = null;
179        rendered = null;
180        required = null;
181        tip = null;
182        value = null;
183        valueChangeListener = null;
184        onchange = null;
185        suggestMethod = null;
186        markup = null;
187        inTag = null;
188        labelTag = null;
189      }
190    
191      public void setMarkup(String markup) {
192        this.markup = markup;
193      }
194    
195      public void setValue(String value) {
196        this.value = value;
197      }
198    
199      public void setValueChangeListener(String valueChangeListener) {
200        this.valueChangeListener = valueChangeListener;
201      }
202    
203      public void setLabel(String label) {
204        this.label = label;
205      }
206    
207      public void setFocus(String focus) {
208        this.focus = focus;
209      }
210    
211      public void setBinding(String binding) {
212        this.binding = binding;
213      }
214    
215      public void setRendered(String rendered) {
216        this.rendered = rendered;
217      }
218    
219      public void setConverter(String converter) {
220        this.converter = converter;
221      }
222    
223      public void setOnchange(String onchange) {
224        this.onchange = onchange;
225      }
226    
227      public void setSuggestMethod(String suggestMethod) {
228        this.suggestMethod = suggestMethod;
229      }
230    
231      public void setValidator(String validator) {
232        this.validator = validator;
233      }
234      public void setPassword(String password) {
235        this.password = password;
236      }
237    
238      public void setReadonly(String readonly) {
239        this.readonly = readonly;
240      }
241    
242      public void setDisabled(String disabled) {
243        this.disabled = disabled;
244      }
245    
246      public void setRequired(String required) {
247        this.required = required;
248      }
249    
250      public void setTip(String tip) {
251        this.tip = tip;
252      }
253    
254      public void setLabelWidth(String labelWidth) {
255        this.labelWidth = labelWidth;
256      }
257    }