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.ExtensionTag;
021    import org.apache.myfaces.tobago.apt.annotation.Tag;
022    import org.apache.myfaces.tobago.taglib.component.FileTag;
023    import org.apache.myfaces.tobago.taglib.component.InputTagDeclaration;
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.HasLabelWidth;
027    import org.apache.myfaces.tobago.taglib.decl.HasTip;
028    import org.apache.myfaces.tobago.taglib.decl.IsDisabled;
029    import org.apache.myfaces.tobago.taglib.decl.IsRequired;
030    
031    import javax.servlet.jsp.JspException;
032    import javax.servlet.jsp.tagext.BodyTagSupport;
033    
034    /**
035     * Renders a file input field with a label.
036     * <p/>
037     * Short syntax of:
038     * <p/>
039     * <pre>
040     * &lt;tc:panel>
041     *   &lt;f:facet name="layout">
042     *     &lt;tc:gridLayout columns="fixed;*"/>
043     *   &lt;/f:facet>
044     *   &lt;tc:label value="#{label}" for="@auto"/>
045     *   &lt;tc:file value="#{value}">
046     *     ...
047     *   &lt;/tc:in>
048     * &lt;/tc:panel>
049     * </pre>
050     */
051    
052    @Tag(name = "file")
053    @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.FileTag")
054    public class FileExtensionTag extends BodyTagSupport
055        implements InputTagDeclaration, HasIdBindingAndRendered, IsDisabled,
056        HasTip, HasLabel, HasLabelWidth, IsRequired {
057    
058      private String binding;
059      private String label;
060      private String value;
061      private String valueChangeListener;
062      private String validator;
063      private String disabled;
064      private String rendered;
065      private String tip;
066      private String onchange;
067      private String labelWidth;
068      private String required;
069      private String tabIndex;
070      private String focus;
071    
072      private LabelExtensionTag labelTag;
073      private FileTag fileTag;
074    
075      @Override
076      public int doStartTag() throws JspException {
077    
078        labelTag = new LabelExtensionTag();
079        labelTag.setPageContext(pageContext);
080        if (label != null) {
081          labelTag.setValue(label);
082        }
083        if (tip != null) {
084          labelTag.setTip(tip);
085        }
086        if (rendered != null) {
087          labelTag.setRendered(rendered);
088        }
089        if (labelWidth != null) {
090          labelTag.setColumns(labelWidth + ";*");
091        }
092        labelTag.setParent(getParent());
093        labelTag.doStartTag();
094    
095        fileTag = new FileTag();
096        fileTag.setPageContext(pageContext);
097        if (value != null) {
098          fileTag.setValue(value);
099        }
100        if (valueChangeListener != null) {
101          fileTag.setValueChangeListener(valueChangeListener);
102        }
103        if (binding != null) {
104          fileTag.setBinding(binding);
105        }
106        if (validator != null) {
107          fileTag.setValidator(validator);
108        }
109        if (disabled != null) {
110          fileTag.setDisabled(disabled);
111        }
112        if (id != null) {
113          fileTag.setId(id);
114        }
115        if (onchange != null) {
116          fileTag.setOnchange(onchange);
117        }
118        if (required != null) {
119          fileTag.setRequired(required);
120        }
121        if (tabIndex != null) {
122          fileTag.setTabIndex(tabIndex);
123        }
124        if (focus != null) {
125          fileTag.setFocus(focus);
126        }
127        fileTag.setParent(labelTag);
128        fileTag.doStartTag();
129    
130        return super.doStartTag();
131      }
132    
133      @Override
134      public int doEndTag() throws JspException {
135        fileTag.doEndTag();
136        labelTag.doEndTag();
137        return super.doEndTag();
138      }
139    
140      @Override
141      public void release() {
142        super.release();
143        binding = null;
144        validator = null;
145        disabled = null;
146        label = null;
147        labelWidth = null;
148        tip = null;
149        onchange = null;
150        value = null;
151        rendered = null;
152        valueChangeListener = null;
153        required = null;
154        tabIndex = null;
155        fileTag = null;
156        labelTag = null;
157        focus = null;
158      }
159    
160      public void setLabel(String label) {
161        this.label = label;
162      }
163    
164      public void setValue(String value) {
165        this.value = value;
166      }
167    
168      public void setValueChangeListener(String valueChangeListener) {
169        this.valueChangeListener = valueChangeListener;
170      }
171    
172      public void setOnchange(String onchange) {
173        this.onchange = onchange;
174      }
175    
176      public void setBinding(String binding) {
177        this.binding = binding;
178      }
179    
180      public void setRendered(String rendered) {
181        this.rendered = rendered;
182      }
183    
184      public void setValidator(String validator) {
185        this.validator = validator;
186      }
187    
188      public void setDisabled(String disabled) {
189        this.disabled = disabled;
190      }
191    
192      public void setTip(String tip) {
193        this.tip = tip;
194      }
195    
196      public void setLabelWidth(String labelWidth) {
197        this.labelWidth = labelWidth;
198      }
199    
200      public void setRequired(String required) {
201        this.required = required;
202      }
203    
204      public void setTabIndex(String tabIndex) {
205        this.tabIndex = tabIndex;
206      }
207    
208      public void setFocus(String focus) {
209        this.focus = focus;
210      }
211    }