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 * <tc:panel> 041 * <f:facet name="layout"> 042 * <tc:gridLayout columns="fixed;*"/> 043 * </f:facet> 044 * <tc:label value="#{label}" for="@auto"/> 045 * <tc:file value="#{value}"> 046 * ... 047 * </tc:in> 048 * </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 071 private LabelExtensionTag labelTag; 072 private FileTag fileTag; 073 074 @Override 075 public int doStartTag() throws JspException { 076 077 labelTag = new LabelExtensionTag(); 078 labelTag.setPageContext(pageContext); 079 if (label != null) { 080 labelTag.setValue(label); 081 } 082 if (tip != null) { 083 labelTag.setTip(tip); 084 } 085 if (rendered != null) { 086 labelTag.setRendered(rendered); 087 } 088 if (labelWidth != null) { 089 labelTag.setColumns(labelWidth + ";*"); 090 } 091 labelTag.setParent(getParent()); 092 labelTag.doStartTag(); 093 094 fileTag = new FileTag(); 095 fileTag.setPageContext(pageContext); 096 if (value != null) { 097 fileTag.setValue(value); 098 } 099 if (valueChangeListener != null) { 100 fileTag.setValueChangeListener(valueChangeListener); 101 } 102 if (binding != null) { 103 fileTag.setBinding(binding); 104 } 105 if (validator != null) { 106 fileTag.setValidator(validator); 107 } 108 if (disabled != null) { 109 fileTag.setDisabled(disabled); 110 } 111 if (id != null) { 112 fileTag.setId(id); 113 } 114 if (onchange != null) { 115 fileTag.setOnchange(onchange); 116 } 117 if (required != null) { 118 fileTag.setRequired(required); 119 } 120 if (tabIndex != null) { 121 fileTag.setTabIndex(tabIndex); 122 } 123 fileTag.setParent(labelTag); 124 fileTag.doStartTag(); 125 126 return super.doStartTag(); 127 } 128 129 @Override 130 public int doEndTag() throws JspException { 131 fileTag.doEndTag(); 132 labelTag.doEndTag(); 133 return super.doEndTag(); 134 } 135 136 @Override 137 public void release() { 138 super.release(); 139 binding = null; 140 validator = null; 141 disabled = null; 142 label = null; 143 labelWidth = null; 144 tip = null; 145 onchange = null; 146 value = null; 147 rendered = null; 148 valueChangeListener = null; 149 required = null; 150 tabIndex = null; 151 fileTag = null; 152 labelTag = null; 153 } 154 155 public void setLabel(String label) { 156 this.label = label; 157 } 158 159 public void setValue(String value) { 160 this.value = value; 161 } 162 163 public void setValueChangeListener(String valueChangeListener) { 164 this.valueChangeListener = valueChangeListener; 165 } 166 167 public void setOnchange(String onchange) { 168 this.onchange = onchange; 169 } 170 171 public void setBinding(String binding) { 172 this.binding = binding; 173 } 174 175 public void setRendered(String rendered) { 176 this.rendered = rendered; 177 } 178 179 public void setValidator(String validator) { 180 this.validator = validator; 181 } 182 183 public void setDisabled(String disabled) { 184 this.disabled = disabled; 185 } 186 187 public void setTip(String tip) { 188 this.tip = tip; 189 } 190 191 public void setLabelWidth(String labelWidth) { 192 this.labelWidth = labelWidth; 193 } 194 195 public void setRequired(String required) { 196 this.required = required; 197 } 198 199 public void setTabIndex(String tabIndex) { 200 this.tabIndex = tabIndex; 201 } 202 }