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 2010/06/17 03:46:27 UTC

svn commit: r955446 - in /myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document: AbstractDocumentBody.java AbstractDocumentRenderer.java DocumentBodyRenderer.java

Author: lu4242
Date: Thu Jun 17 01:46:26 2010
New Revision: 955446

URL: http://svn.apache.org/viewvc?rev=955446&view=rev
Log:
TOMAHAWK-1474 Behavior support for components that contains event aware properties in jsf 2.0 module and make t:documentHead and t:documentBody render component resources

Added:
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentBody.java
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentRenderer.java
Modified:
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentBody.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentBody.java?rev=955446&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentBody.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentBody.java Thu Jun 17 01:46:26 2010
@@ -0,0 +1,70 @@
+/*
+ * 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.document;
+
+import javax.faces.component.behavior.ClientBehaviorHolder;
+
+import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFProperty;
+import org.apache.myfaces.component.EventAware;
+import org.apache.myfaces.component.StyleAware;
+import org.apache.myfaces.component.UniversalProperties;
+
+/**
+ * Document to enclose the document body. If not otherwise possible you can use
+ * state="start|end" to demarkate the document boundaries
+ * 
+ * @JSFComponent
+ *   name = "t:documentBody"
+ *   class = "org.apache.myfaces.custom.document.DocumentBody"
+ *   tagClass = "org.apache.myfaces.custom.document.DocumentBodyTag"
+ * @since 1.1.7
+ * @author Mario Ivankovits (latest modification by $Author: lu4242 $)
+ * @version $Revision: 691871 $ $Date: 2008-09-03 23:32:08 -0500 (mié, 03 sep 2008) $
+ */
+abstract class AbstractDocumentBody extends AbstractDocument 
+    implements StyleAware, EventAware, UniversalProperties, ClientBehaviorHolder
+{
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.DocumentBody";
+    private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.DocumentBody";
+
+    public AbstractDocumentBody()
+    {
+        super(DEFAULT_RENDERER_TYPE);
+    }
+    
+    /**
+     * HTML: Script to be invoked when the page is loaded
+     * 
+     */
+    @JSFProperty(clientEvent="load")
+    public abstract String getOnload();
+    
+    /**
+     * HTML: Script to be invoked when the page is unloaded
+     * 
+     */
+    @JSFProperty(clientEvent="unload")
+    public abstract String getOnunload();
+
+    /**
+     * 
+     */
+    @JSFProperty(clientEvent="resize")
+    public abstract String getOnresize();
+}
\ No newline at end of file

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentRenderer.java?rev=955446&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentRenderer.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/AbstractDocumentRenderer.java Thu Jun 17 01:46:26 2010
@@ -0,0 +1,90 @@
+/*
+ * 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.document;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+
+import org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils;
+
+/**
+ * Base class to handle the document family
+ *
+ * @author Mario Ivankovits (latest modification by $Author: skitching $)
+ * @version $Revision: 673833 $ $Date: 2008-07-03 16:58:05 -0500 (jue, 03 jul 2008) $
+ */
+public abstract class AbstractDocumentRenderer extends Renderer
+{
+    protected abstract String getHtmlTag();
+    protected abstract Class getDocumentClass();
+
+    public void encodeBegin(FacesContext facesContext, UIComponent uiComponent)
+            throws IOException
+    {
+        RendererUtils.checkParamValidity(facesContext, uiComponent,
+                getDocumentClass());
+
+        AbstractDocument document = (AbstractDocument) uiComponent;
+
+        ResponseWriter writer = facesContext.getResponseWriter();
+
+        if (document.hasState() && document.isEndState())
+        {
+            closeTag(facesContext, writer);
+        }
+        else
+        {
+            openTag(facesContext, writer, uiComponent);
+        }
+    }
+
+    protected void openTag(FacesContext facesContext, ResponseWriter writer, UIComponent uiComponent)
+        throws IOException
+    {
+        writer.startElement(getHtmlTag(), uiComponent);
+    }
+
+    protected void closeTag(FacesContext facesContext, ResponseWriter writer)
+        throws IOException
+    {
+        writeBeforeEnd(facesContext);
+        writer.endElement(getHtmlTag());
+    }
+
+    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
+            throws IOException
+    {
+        AbstractDocument document = (AbstractDocument) uiComponent;
+
+        ResponseWriter writer = facesContext.getResponseWriter();
+
+        if (!document.hasState())
+        {
+            closeTag(facesContext, writer);
+        }
+    }
+
+    protected void writeBeforeEnd(FacesContext facesContext) throws IOException
+    {
+    }
+}
\ No newline at end of file

Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java?rev=955446&r1=955445&r2=955446&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/document/DocumentBodyRenderer.java Thu Jun 17 01:46:26 2010
@@ -19,15 +19,23 @@
 package org.apache.myfaces.custom.document;
 
 import java.io.IOException;
+import java.util.List;
+import java.util.Map;
 
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIViewRoot;
+import javax.faces.component.behavior.ClientBehavior;
+import javax.faces.component.behavior.ClientBehaviorHolder;
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
 import org.apache.myfaces.renderkit.html.util.AddResource;
 import org.apache.myfaces.renderkit.html.util.AddResourceFactory;
 import org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.JavascriptUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.ResourceUtils;
+import org.apache.myfaces.shared_tomahawk.renderkit.ClientBehaviorEvents;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.HTML;
 import org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils;
 import org.apache.myfaces.tomahawk.util.TomahawkResourceUtils;
 
@@ -48,6 +56,9 @@ public class DocumentBodyRenderer extend
     public static final String RENDERER_TYPE = "org.apache.myfaces.DocumentBody";
     private String BODY_ELEM = "body";
     private String[] ATTRS = new String[] {"onload", "onunload", "onresize", "onkeypress", "style", "styleClass", "id"};
+    
+    private final String ONRESIZE = "onresize";
+    private final String RESIZE = "resize";
 
     protected String getHtmlTag()
     {
@@ -59,11 +70,49 @@ public class DocumentBodyRenderer extend
         return DocumentBody.class;
     }
 
-    protected void openTag(ResponseWriter writer, UIComponent uiComponent)
-    throws IOException
+    protected void openTag(FacesContext facesContext, ResponseWriter writer, UIComponent uiComponent)
+        throws IOException
     {
-        super.openTag(writer, uiComponent);
-        HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, ATTRS);
+        //HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, ATTRS);
+        
+        Map<String, List<ClientBehavior>> behaviors = null;
+        if (uiComponent instanceof ClientBehaviorHolder && JavascriptUtils.isJavascriptAllowed(facesContext.getExternalContext()))
+        {
+            behaviors = ((ClientBehaviorHolder) uiComponent).getClientBehaviors();
+            if (!behaviors.isEmpty())
+            {
+                ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer);
+            }
+            super.openTag(facesContext, writer, uiComponent);
+            
+            if (behaviors.isEmpty())
+            {
+                HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
+            }
+            else
+            {
+                writer.writeAttribute(HTML.ID_ATTR, uiComponent.getClientId(facesContext), null);
+            }
+            
+            HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, uiComponent, behaviors);
+            HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONLOAD_ATTR, uiComponent,
+                    ClientBehaviorEvents.LOAD, behaviors, HTML.ONLOAD_ATTR);
+            HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONUNLOAD_ATTR, uiComponent,
+                    ClientBehaviorEvents.UNLOAD, behaviors, HTML.ONUNLOAD_ATTR);
+            HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, ONRESIZE, uiComponent,
+                    RESIZE, behaviors, ONRESIZE);
+            
+            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
+                    HTML.BODY_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
+        }
+        else
+        {
+            super.openTag(facesContext, writer, uiComponent);
+            HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
+            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent,
+                    HTML.BODY_PASSTHROUGH_ATTRIBUTES);
+            HtmlRendererUtils.renderHTMLAttribute(writer, uiComponent, ONRESIZE, ONRESIZE);
+        }
     }
 
     protected void writeBeforeEnd(FacesContext facesContext) throws IOException