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:56:05 UTC

svn commit: r955449 - in /myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage: AbstractHtmlSwapImage.java HtmlSwapImageRenderer.java

Author: lu4242
Date: Thu Jun 17 01:56:04 2010
New Revision: 955449

URL: http://svn.apache.org/viewvc?rev=955449&view=rev
Log:
TOMAHAWK-1474 Behavior support for components that contains event aware properties in jsf 2.0 module

Added:
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/AbstractHtmlSwapImage.java
Modified:
    myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/HtmlSwapImageRenderer.java

Added: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/AbstractHtmlSwapImage.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/AbstractHtmlSwapImage.java?rev=955449&view=auto
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/AbstractHtmlSwapImage.java (added)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/AbstractHtmlSwapImage.java Thu Jun 17 01:56:04 2010
@@ -0,0 +1,143 @@
+/*
+ * 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.swapimage;
+
+import javax.faces.component.UIGraphic;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+
+import org.apache.myfaces.component.AlignProperty;
+import org.apache.myfaces.component.EventAware;
+import org.apache.myfaces.component.StyleAware;
+import org.apache.myfaces.component.UniversalProperties;
+import org.apache.myfaces.component.UserRoleUtils;
+
+/**
+ * Unless otherwise specified, all attributes accept static values or EL expressions.
+ * 
+ * @JSFComponent
+ *   name = "t:swapImage"
+ *   class = "org.apache.myfaces.custom.swapimage.HtmlSwapImage"
+ *   tagClass = "org.apache.myfaces.custom.swapimage.HtmlSwapImageTag"
+ * @since 1.1.7
+ * @author Thomas Spiegl
+ * @version $Revision: 691856 $ $Date: 2008-09-03 21:40:30 -0500 (mié, 03 sep 2008) $
+ */
+public abstract class AbstractHtmlSwapImage extends UIGraphic
+    implements UniversalProperties, AlignProperty, StyleAware, EventAware, ClientBehaviorHolder
+{
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlSwapImage";
+    public static final String COMPONENT_FAMILY = "javax.faces.Graphic";
+    private static final String DEFAULT_RENDERER_TYPE = "org.apache.myfaces.SwapImage";
+    private static final boolean DEFAULT_ISMAP = false;
+
+    /**
+     * HTML: Specifies the width of the border of this element, in pixels. Deprecated in HTML 4.01.
+     * 
+     * @JSFProperty
+     *   defaultValue="Integer.MIN_VALUE"
+     */
+    public abstract String getBorder();
+
+    /**
+     * HTML: The amount of white space to be inserted to the left and 
+     * right of this element, in undefined units. 
+     * Deprecated in HTML 4.01.
+     * 
+     * @JSFProperty
+     */
+    public abstract String getHspace();
+    
+    /**
+     *  HTML: The amount of white space to be inserted above and 
+     *  below this element, in undefined units. 
+     *  Deprecated in HTML 4.01.
+     * 
+     * @JSFProperty
+     */
+    public abstract String getVspace();
+    
+    /**
+     * the url of the image displayed onmouseover
+     * 
+     * @JSFProperty
+     *   required="true"
+     */
+    public abstract String getSwapImageUrl();
+
+    /**
+     * activeImage will be rendered if: swapImage is a direct 
+     * child of commandNavigation and the commandNavigation.isActive
+     * 
+     * @JSFProperty
+     */
+    public abstract String getActiveImageUrl();
+
+    /**
+     * HTML: Specifies alternative text that can be used by a browser 
+     * that can't show this element.
+     * 
+     * @JSFProperty
+     */
+    public abstract String getAlt();
+
+    /**
+     * HTML: Overrides the natural height of this image, by specifying 
+     * height in pixels.
+     * 
+     * @JSFProperty
+     */
+    public abstract String getHeight();
+
+    /**
+     * HTML: Specifies server-side image map handling for this image.
+     * 
+     * @JSFProperty
+     *   defaultValue = "false"
+     */
+    public abstract boolean isIsmap();
+
+    /**
+     * HTML: A link to a long description of the image.
+     * 
+     * @JSFProperty
+     */
+    public abstract String getLongdesc();
+
+    /**
+     * HTML: Specifies an image map to use with this image.
+     * 
+     * @JSFProperty
+     */
+    public abstract String getUsemap();
+
+    /**
+     * HTML: Overrides the natural width of this image, by 
+     * specifying width in pixels.
+     * 
+     * @JSFProperty
+     */
+    public abstract String getWidth();
+
+    public boolean isRendered()
+    {
+        if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
+        return super.isRendered();
+    }
+
+}

Modified: myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/HtmlSwapImageRenderer.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/HtmlSwapImageRenderer.java?rev=955449&r1=955448&r2=955449&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/HtmlSwapImageRenderer.java (original)
+++ myfaces/tomahawk/trunk/core20/src/main/java/org/apache/myfaces/custom/swapimage/HtmlSwapImageRenderer.java Thu Jun 17 01:56:04 2010
@@ -19,21 +19,27 @@
 package org.apache.myfaces.custom.swapimage;
 
 import java.io.IOException;
+import java.util.List;
+import java.util.Map;
 
 import javax.faces.application.ResourceDependency;
 import javax.faces.component.UIComponent;
 import javax.faces.component.UIGraphic;
+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.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.myfaces.custom.navigation.HtmlCommandNavigation;
+import org.apache.myfaces.shared_tomahawk.renderkit.ClientBehaviorEvents;
 import org.apache.myfaces.shared_tomahawk.renderkit.JSFAttr;
 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;
+import org.apache.myfaces.shared_tomahawk.renderkit.html.util.ResourceUtils;
 
 /**
  * @JSFRenderer
@@ -50,6 +56,14 @@ public class HtmlSwapImageRenderer
 {
     private static final Log log = LogFactory.getLog(HtmlSwapImageRenderer.class);
 
+    @Override
+    public void decode(FacesContext context, UIComponent component)
+    {
+        super.decode(context, component);
+        
+        HtmlRendererUtils.decodeClientBehaviors(context, component);
+    }
+    
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
             throws IOException
     {
@@ -59,23 +73,24 @@ public class HtmlSwapImageRenderer
 
         //AddResourceFactory.getInstance(facesContext).addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN,
         //        HtmlSwapImage.class, "swapimage.js");
+        
+        HtmlSwapImage swapImage = (HtmlSwapImage) uiComponent;
+        
+        Map<String, List<ClientBehavior>> behaviors = swapImage.getClientBehaviors();
+        if (!behaviors.isEmpty())
+        {
+            ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, facesContext.getResponseWriter());
+        }
 
         String url;
-        if (uiComponent instanceof HtmlSwapImage)
+        if (uiComponent.getParent() instanceof HtmlCommandNavigation)
         {
-            if (uiComponent.getParent() instanceof HtmlCommandNavigation)
-            {
-                url = ((HtmlCommandNavigation) uiComponent.getParent()).isActive() ?
-                    ((HtmlSwapImage) uiComponent).getActiveImageUrl() : ((HtmlSwapImage)uiComponent).getUrl();
-            }
-            else
-            {
-                url = ((HtmlSwapImage)uiComponent).getUrl();
-            }
+            url = ((HtmlCommandNavigation) uiComponent.getParent()).isActive() ?
+                ((HtmlSwapImage) uiComponent).getActiveImageUrl() : ((HtmlSwapImage)uiComponent).getUrl();
         }
         else
         {
-            url = (String)uiComponent.getAttributes().get(JSFAttr.URL_ATTR);
+            url = ((HtmlSwapImage)uiComponent).getUrl();
         }
 
         if ((url != null) && (url.length() > 0))
@@ -90,21 +105,50 @@ public class HtmlSwapImageRenderer
                                      facesContext.getExternalContext().encodeResourceURL(src),
                                      null);
 
-            if (uiComponent instanceof HtmlSwapImage)
+            String swapImageUrl = ((HtmlSwapImage) uiComponent).getSwapImageUrl();
+            swapImageUrl = facesContext.getApplication()
+            .getViewHandler().getResourceURL(facesContext, swapImageUrl);
+
+            if (behaviors != null && !behaviors.isEmpty())
             {
-                String swapImageUrl = ((HtmlSwapImage) uiComponent).getSwapImageUrl();
-                swapImageUrl = facesContext.getApplication()
-                .getViewHandler().getResourceURL(facesContext, swapImageUrl);
+                if (swapImageUrl != null)
+                {
+                    HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONMOUSEOVER_ATTR, uiComponent, 
+                            ClientBehaviorEvents.MOUSEOVER, null, behaviors, HTML.ONMOUSEOVER_ATTR, swapImage.getOnmouseover(),
+                            "SI_MM_swapImage('" + getClientId(facesContext, uiComponent) + "','','" + facesContext.getExternalContext().encodeResourceURL(swapImageUrl) + "',1);");
+                    HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONMOUSEOUT_ATTR, uiComponent, 
+                            ClientBehaviorEvents.MOUSEOUT, null, behaviors, HTML.ONMOUSEOUT_ATTR, swapImage.getOnmouseout(),
+                            "SI_MM_swapImgRestore();");
+                }
+                else
+                {
+                    HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONMOUSEOVER_ATTR, uiComponent, 
+                            ClientBehaviorEvents.MOUSEOVER, null, behaviors, HTML.ONMOUSEOVER_ATTR, swapImage.getOnmouseover(), null);
+                    HtmlRendererUtils.renderBehaviorizedAttribute(facesContext, writer, HTML.ONMOUSEOUT_ATTR, uiComponent, 
+                            ClientBehaviorEvents.MOUSEOUT, null, behaviors, HTML.ONMOUSEOUT_ATTR, swapImage.getOnmouseout(), null);
+                }
+                
+                HtmlRendererUtils.renderBehaviorizedEventHandlersWithoutOnmouseoverAndOnmouseout(facesContext, writer, uiComponent, behaviors);
 
+                HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.UNIVERSAL_ATTRIBUTES);
+                HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_ATTRIBUTES);
+            }
+            else
+            {
                 if (swapImageUrl != null)
                 {
                     writer.writeAttribute(HTML.ONMOUSEOVER_ATTR, "SI_MM_swapImage('" + getClientId(facesContext, uiComponent) + "','','" + facesContext.getExternalContext().encodeResourceURL(swapImageUrl) + "',1);", null);
                     writer.writeAttribute(HTML.ONMOUSEOUT_ATTR, "SI_MM_swapImgRestore();", null);
                 }
+                else
+                {
+                    HtmlRendererUtils.renderHTMLAttribute(writer, uiComponent, HTML.ONMOUSEOVER_ATTR, HTML.ONMOUSEOVER_ATTR);
+                    HtmlRendererUtils.renderHTMLAttribute(writer, uiComponent, HTML.ONMOUSEOUT_ATTR, HTML.ONMOUSEOUT_ATTR);
+                }
+                
+                HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES_WITHOUT_ONMOUSEOVER_AND_ONMOUSEOUT);
             }
 
-            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES_WITHOUT_ONMOUSEOVER_AND_ONMOUSEOUT);
-
             writer.endElement(HTML.IMG_ELEM);
         }
         else