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