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