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.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.HasTip; 027 import org.apache.myfaces.tobago.taglib.decl.IsDisabled; 028 import org.apache.myfaces.tobago.taglib.decl.HasLabelWidth; 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 * 037 * Short syntax of: 038 * 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 070 private LabelExtensionTag labelTag; 071 private FileTag fileTag; 072 073 @Override 074 public int doStartTag() throws JspException { 075 076 labelTag = new LabelExtensionTag(); 077 labelTag.setPageContext(pageContext); 078 if (label != null) { 079 labelTag.setValue(label); 080 } 081 if (tip != null) { 082 labelTag.setTip(tip); 083 } 084 if (rendered != null) { 085 labelTag.setRendered(rendered); 086 } 087 if (labelWidth != null) { 088 labelTag.setColumns(labelWidth + ";*"); 089 } 090 labelTag.setParent(getParent()); 091 labelTag.doStartTag(); 092 093 fileTag = new FileTag(); 094 fileTag.setPageContext(pageContext); 095 if (value != null) { 096 fileTag.setValue(value); 097 } 098 if (valueChangeListener != null) { 099 fileTag.setValueChangeListener(valueChangeListener); 100 } 101 if (binding != null) { 102 fileTag.setBinding(binding); 103 } 104 if (validator != null) { 105 fileTag.setValidator(validator); 106 } 107 if (disabled != null) { 108 fileTag.setDisabled(disabled); 109 } 110 if (id != null) { 111 fileTag.setId(id); 112 } 113 if (onchange != null) { 114 fileTag.setOnchange(onchange); 115 } 116 if (required != null) { 117 fileTag.setRequired(required); 118 } 119 fileTag.setParent(labelTag); 120 fileTag.doStartTag(); 121 122 return super.doStartTag(); 123 } 124 125 @Override 126 public int doEndTag() throws JspException { 127 fileTag.doEndTag(); 128 labelTag.doEndTag(); 129 return super.doEndTag(); 130 } 131 132 @Override 133 public void release() { 134 super.release(); 135 binding = null; 136 validator = null; 137 disabled = null; 138 label = null; 139 labelWidth = null; 140 tip = null; 141 onchange = null; 142 value = null; 143 rendered = null; 144 valueChangeListener = null; 145 required = null; 146 fileTag = null; 147 labelTag = null; 148 } 149 150 public void setLabel(String label) { 151 this.label = label; 152 } 153 154 public void setValue(String value) { 155 this.value = value; 156 } 157 158 public void setValueChangeListener(String valueChangeListener) { 159 this.valueChangeListener = valueChangeListener; 160 } 161 162 public void setOnchange(String onchange) { 163 this.onchange = onchange; 164 } 165 166 public void setBinding(String binding) { 167 this.binding = binding; 168 } 169 170 public void setRendered(String rendered) { 171 this.rendered = rendered; 172 } 173 174 public void setValidator(String validator) { 175 this.validator = validator; 176 } 177 178 public void setDisabled(String disabled) { 179 this.disabled = disabled; 180 } 181 182 public void setTip(String tip) { 183 this.tip = tip; 184 } 185 186 public void setLabelWidth(String labelWidth) { 187 this.labelWidth = labelWidth; 188 } 189 190 public void setRequired(String required) { 191 this.required = required; 192 } 193 }