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.commons.logging.Log; 021 import org.apache.commons.logging.LogFactory; 022 023 import static org.apache.myfaces.tobago.TobagoConstants.FACET_LAYOUT; 024 import org.apache.myfaces.tobago.apt.annotation.ExtensionTag; 025 import org.apache.myfaces.tobago.apt.annotation.Tag; 026 import org.apache.myfaces.tobago.taglib.component.GridLayoutTag; 027 import org.apache.myfaces.tobago.taglib.component.LabelTag; 028 import org.apache.myfaces.tobago.taglib.component.PanelTag; 029 import org.apache.myfaces.tobago.taglib.decl.HasTip; 030 import org.apache.myfaces.tobago.taglib.decl.HasValue; 031 import org.apache.myfaces.tobago.util.LayoutUtil; 032 033 import javax.faces.webapp.FacetTag; 034 import javax.faces.webapp.UIComponentTag; 035 import javax.servlet.jsp.JspException; 036 import javax.servlet.jsp.tagext.BodyTagSupport; 037 038 @Tag(name = "label") 039 @ExtensionTag(baseClassName = "org.apache.myfaces.tobago.taglib.component.LabelTag") 040 public class LabelExtensionTag extends BodyTagSupport 041 implements HasValue, HasTip { 042 043 private static final Log LOG = LogFactory.getLog(LabelExtensionTag.class); 044 045 public static final String DEFAULT_COLUMNS = "fixed;*"; 046 047 private String value; 048 private String tip; 049 private String rendered; 050 private String columns = DEFAULT_COLUMNS; 051 private String rows = "fixed"; 052 053 private PanelTag panelTag; 054 055 @Override 056 public int doStartTag() throws JspException { 057 058 panelTag = new PanelTag(); 059 panelTag.setPageContext(pageContext); 060 panelTag.setParent(getParent()); 061 if (rendered != null) { 062 panelTag.setRendered(rendered); 063 } 064 panelTag.doStartTag(); 065 066 FacetTag facetTag = new FacetTag(); 067 facetTag.setPageContext(pageContext); 068 facetTag.setName(FACET_LAYOUT); 069 facetTag.setParent(panelTag); 070 facetTag.doStartTag(); 071 072 GridLayoutTag gridLayoutTag = new GridLayoutTag(); 073 gridLayoutTag.setPageContext(pageContext); 074 gridLayoutTag.setColumns(columns); 075 gridLayoutTag.setRows(rows); 076 gridLayoutTag.setParent(facetTag); 077 gridLayoutTag.doStartTag(); 078 gridLayoutTag.doEndTag(); 079 080 facetTag.doEndTag(); 081 082 LabelTag labelTag = new LabelTag(); 083 labelTag.setPageContext(pageContext); 084 if (value != null) { 085 labelTag.setValue(value); 086 } 087 if (tip != null) { 088 labelTag.setTip(tip); 089 } 090 labelTag.setFor("@auto"); 091 labelTag.setParent(panelTag); 092 labelTag.doStartTag(); 093 labelTag.doEndTag(); 094 095 return super.doStartTag(); 096 } 097 098 @Override 099 public int doEndTag() throws JspException { 100 panelTag.doEndTag(); 101 return super.doEndTag(); 102 } 103 104 @Override 105 public void release() { 106 super.release(); 107 value = null; 108 tip = null; 109 rendered = null; 110 columns = DEFAULT_COLUMNS; 111 rows = "fixed"; 112 panelTag = null; 113 } 114 115 public void setValue(String value) { 116 this.value = value; 117 } 118 119 public void setTip(String tip) { 120 this.tip = tip; 121 } 122 123 public void setRendered(String rendered) { 124 this.rendered = rendered; 125 } 126 127 void setColumns(String columns) { 128 if (!(UIComponentTag.isValueReference(columns) || LayoutUtil.checkTokens(columns))) { 129 LOG.warn("Illegal value for columns = \"" + columns + "\" replacing with default: \"" + DEFAULT_COLUMNS + "\""); 130 this.columns = DEFAULT_COLUMNS; 131 } else { 132 this.columns = columns; 133 } 134 } 135 136 void setRows(String rows) { 137 this.rows = rows; 138 } 139 }