You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/06/23 23:01:17 UTC

svn commit: r670752 - in /myfaces/tomahawk/trunk: core/src/site/xdoc/ core12/src/main/java/org/apache/myfaces/custom/htmlTag/

Author: lu4242
Date: Mon Jun 23 14:01:16 2008
New Revision: 670752

URL: http://svn.apache.org/viewvc?rev=670752&view=rev
Log:
TOMAHAWK-64 Allow t:htmlTag to support an attributes string.

Added:
    myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/
    myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java   (with props)
    myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java   (with props)
Modified:
    myfaces/tomahawk/trunk/core/src/site/xdoc/htmlTag.xml

Modified: myfaces/tomahawk/trunk/core/src/site/xdoc/htmlTag.xml
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core/src/site/xdoc/htmlTag.xml?rev=670752&r1=670751&r2=670752&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core/src/site/xdoc/htmlTag.xml (original)
+++ myfaces/tomahawk/trunk/core/src/site/xdoc/htmlTag.xml Mon Jun 23 14:01:16 2008
@@ -8,7 +8,8 @@
         <section name="Description">
             
             <p>
-                Renders any HTML tag as specified in value attribute.
+                Renders any HTML tag as specified in value attribute. Additional tag attributes can be supplied
+                by nested &lt;f:param&gt; tags (only on tomahawk12).
             </p>
 
         </section>
@@ -58,7 +59,9 @@
         <section name="Usage">
             
             <source xml:space="preserve">
-&lt;t:htmlTag [{all standard UIOutput attributes}] /&gt;
+&lt;t:htmlTag [{all standard UIOutput attributes}]&gt;
+  &lt;f:param name="AttributeName" value="AttributeValue" /&gt;
+&lt;/t:htmlTag&gt;
             </source>
         </section>
         <!-- Syntax -->
@@ -80,8 +83,16 @@
 [Other JSF tags/content]
 &lt;/t:htmlTag&gt;
             </p>
+            <p>
+OR<br/>
+&lt;t:htmlTag value="link"&gt;<br/>
+  &lt;f:param name="rel" value="stylesheet"/&gt;<br/>
+  &lt;f:param name="type" value="text/css"/&gt;<br/>
+  &lt;f:param name="href" value="#{userPrefs.stylesheet}"/&gt;<br/>
+&lt;/t:htmlTag&gt;
+            </p>
         </section>
     </body>
     
 
-</document>
\ No newline at end of file
+</document>

Added: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java?rev=670752&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java (added)
+++ myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java Mon Jun 23 14:01:16 2008
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.htmlTag;
+
+import javax.faces.component.UIOutput;
+import javax.faces.context.FacesContext;
+
+import org.apache.myfaces.component.ForceIdAware;
+import org.apache.myfaces.component.StyleAware;
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.UserRoleUtils;
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+
+/**
+ * Creates an arbitrary HTML tag which encloses any child components. 
+ * The value attribute specifies the name of the generated tag.
+ * <br/>
+ * If value is an empty string then no tag will be generated, but 
+ * the child components will be rendered. This differs from setting 
+ * rendered=false, which prevents child components from being 
+ * rendered at all.
+ * <br/>
+ * You can specify some attribute to be added to the component 
+ * using f:param like this:
+ * <br/>
+ * <t:htmlTag value="span">
+ *       <f:param name="title" value="Hello world!"/>
+ * </t:htmlTag>
+ * 
+ * Unless otherwise specified, all attributes accept static values or EL expressions.
+ * 
+ * @JSFComponent
+ *   name = "t:htmlTag"
+ *   class = "org.apache.myfaces.custom.htmlTag.HtmlTag"
+ *   tagClass = "org.apache.myfaces.custom.htmlTag.HtmlTagTag"
+ *   
+ * @JSFJspProperty
+ *   name = "converter"
+ *   returnType = "javax.faces.convert.Converter"
+ *   tagExcluded = "true"
+ * 
+ * @author bdudney (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public abstract class AbstractHtmlTag extends UIOutput 
+    implements UserRoleAware, StyleAware, ForceIdAware
+{
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlTag";
+    public static final String COMPONENT_FAMILY = "javax.faces.Output";
+    private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.HtmlTagRenderer";
+
+    public String getClientId(FacesContext context)
+    {
+        String clientId = HtmlComponentUtils.getClientId(this,
+                getRenderer(context), context);
+        if (clientId == null)
+        {
+            clientId = super.getClientId(context);
+        }
+
+        return clientId;
+    }
+    
+    public boolean isRendered()
+    {
+        if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
+        return super.isRendered();
+    }
+
+}
\ No newline at end of file

Propchange: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/AbstractHtmlTag.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java?rev=670752&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java (added)
+++ myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java Mon Jun 23 14:01:16 2008
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.myfaces.custom.htmlTag;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRenderer;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
+
+/**
+ * @JSFRenderer
+ *   renderKitId = "HTML_BASIC" 
+ *   family = "javax.faces.Output"
+ *   type = "org.apache.myfaces.HtmlTagRenderer"
+ * 
+ * @author bdudney (latest modification by $Author$)
+ * @version $Revision$ $Date$
+ */
+public class HtmlTagRenderer extends HtmlRenderer
+{
+    public static final String RENDERER_TYPE = "org.apache.myfaces.HtmlTagRenderer";
+
+    public void encodeBegin(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        if ((context == null) || (component == null))
+        {
+            throw new NullPointerException();
+        }
+        HtmlTag htmlTag = (HtmlTag) component;
+
+        if (htmlTag.isRendered())
+        {
+            String tag = htmlTag.getValue().toString();
+            if( tag.trim().length() == 0 ) // Don't render the tag, but render the children.
+                return;
+
+            ResponseWriter writer = context.getResponseWriter();
+
+            writer.startElement(tag, htmlTag);
+            HtmlRendererUtils.writeIdIfNecessary(writer, htmlTag, context);
+
+            // TODO : Use HtmlRendererUtils.renderHTMLAttributes(writer, component, HTML.COMMON_PASSTROUGH_ATTRIBUTES);
+            String[] supportedAttributes = {HTML.STYLE_CLASS_ATTR, HTML.STYLE_ATTR};
+            HtmlRendererUtils.renderHTMLAttributes(writer, htmlTag, supportedAttributes);
+            
+            // write additional attributes supplied by f:param tags
+            Map params = HtmlComponentUtils.getParameterMap(htmlTag);
+            for(Iterator iter = params.entrySet().iterator(); iter.hasNext();)
+            {
+                Entry param = (Entry) iter.next();
+                writer.writeAttribute(param.getKey().toString(), param.getValue().toString(), null);
+            }
+        }
+    }
+
+    public void encodeChildren(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        RendererUtils.renderChildren(context, component);
+    }
+    
+    public boolean getRendersChildren()
+    {
+        return true;
+    }
+
+    public void encodeEnd(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        if ((context == null) || (component == null))
+        {
+            throw new NullPointerException();
+        }
+        HtmlTag htmlTag = (HtmlTag) component;
+
+        if (htmlTag.isRendered())
+        {
+            String tag = htmlTag.getValue().toString();
+            if( tag.trim().length() == 0 )
+                return;
+
+            ResponseWriter writer = context.getResponseWriter();
+            // force separate end tag
+            writer.writeText("", null);            
+            writer.endElement( tag );
+        }
+    }
+}

Propchange: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/tomahawk/trunk/core12/src/main/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL