You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by mm...@apache.org on 2005/06/05 12:18:11 UTC

svn commit: r180077 - in /myfaces/trunk: conf/ src/components/org/apache/myfaces/component/html/ext/ src/components/org/apache/myfaces/renderkit/html/ext/ src/components/org/apache/myfaces/taglib/html/ext/ src/myfaces/org/apache/myfaces/application/ src/myfaces/org/apache/myfaces/renderkit/html/ src/share/org/apache/myfaces/renderkit/html/ tlds/

Author: mmarinschek
Date: Sun Jun  5 03:18:07 2005
New Revision: 180077

URL: http://svn.apache.org/viewcvs?rev=180077&view=rev
Log:
HtmlGraphicImage now also as extended component (with user role support), small fix in ApplicationImpl

Added:
    myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.java
    myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.xml
    myfaces/trunk/src/components/org/apache/myfaces/renderkit/html/ext/HtmlImageRenderer.java
    myfaces/trunk/src/components/org/apache/myfaces/taglib/html/ext/HtmlGraphicImageTag.java
    myfaces/trunk/src/share/org/apache/myfaces/renderkit/html/HtmlImageRendererBase.java
Modified:
    myfaces/trunk/conf/faces-config.xml
    myfaces/trunk/src/myfaces/org/apache/myfaces/application/ApplicationImpl.java
    myfaces/trunk/src/myfaces/org/apache/myfaces/renderkit/html/HtmlImageRenderer.java
    myfaces/trunk/tlds/myfaces_ext.tld

Modified: myfaces/trunk/conf/faces-config.xml
URL: http://svn.apache.org/viewcvs/myfaces/trunk/conf/faces-config.xml?rev=180077&r1=180076&r2=180077&view=diff
==============================================================================
--- myfaces/trunk/conf/faces-config.xml (original)
+++ myfaces/trunk/conf/faces-config.xml Sun Jun  5 03:18:07 2005
@@ -57,6 +57,11 @@
     <component-type>org.apache.myfaces.HtmlInputTextarea</component-type>
     <component-class>org.apache.myfaces.component.html.ext.HtmlInputTextarea</component-class>
   </component>
+  
+  <component>
+    <component-type>org.apache.myfaces.HtmlGraphicImage</component-type>
+    <component-class>org.apache.myfaces.component.html.ext.HtmlGraphicImage</component-class>
+  </component>
 
   <component>
     <component-type>org.apache.myfaces.HtmlMessage</component-type>
@@ -384,6 +389,12 @@
             <component-family>javax.faces.Panel</component-family>
             <renderer-type>org.apache.myfaces.Group</renderer-type>
             <renderer-class>org.apache.myfaces.renderkit.html.ext.HtmlGroupRenderer</renderer-class>
+        </renderer>
+
+		<renderer>
+            <component-family>javax.faces.Graphic</component-family>
+            <renderer-type>org.apache.myfaces.Image</renderer-type>
+            <renderer-class>org.apache.myfaces.renderkit.html.ext.HtmlImageRenderer</renderer-class>
         </renderer>
 
         <renderer>

Added: myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.java?rev=180077&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.java (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.java Sun Jun  5 03:18:07 2005
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.component.html.ext;
+
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.UserRoleUtils;
+import org.apache.myfaces.component.html.util.HtmlComponentUtils;
+
+import javax.faces.context.FacesContext;
+import javax.faces.el.ValueBinding;
+
+/**
+ * @author Bruno Aranda
+ * @version $Revision$ $Date: 2005-05-11 17:34:57 +0200 (Wed, 11 May 2005) $
+ */
+public class HtmlGraphicImage
+        extends javax.faces.component.html.HtmlGraphicImage
+        implements UserRoleAware
+{
+    public String getClientId(FacesContext context)
+    {
+        String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
+        if (clientId == null)
+        {
+            clientId = super.getClientId(context);
+        }
+
+        return clientId;
+    }
+
+    //------------------ GENERATED CODE BEGIN (do not modify!) --------------------
+
+    public static final String COMPONENT_TYPE = "org.apache.myfaces.HtmlGraphicImage";
+
+    private String _enabledOnUserRole = null;
+    private String _visibleOnUserRole = null;
+
+    public HtmlGraphicImage()
+    {
+    }
+
+
+    public void setEnabledOnUserRole(String enabledOnUserRole)
+    {
+        _enabledOnUserRole = enabledOnUserRole;
+    }
+
+    public String getEnabledOnUserRole()
+    {
+        if (_enabledOnUserRole != null) return _enabledOnUserRole;
+        ValueBinding vb = getValueBinding("enabledOnUserRole");
+        return vb != null ? (String)vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setVisibleOnUserRole(String visibleOnUserRole)
+    {
+        _visibleOnUserRole = visibleOnUserRole;
+    }
+
+    public String getVisibleOnUserRole()
+    {
+        if (_visibleOnUserRole != null) return _visibleOnUserRole;
+        ValueBinding vb = getValueBinding("visibleOnUserRole");
+        return vb != null ? (String)vb.getValue(getFacesContext()) : null;
+    }
+
+
+    public boolean isRendered()
+    {
+        if (!UserRoleUtils.isVisibleOnUserRole(this)) return false;
+        return super.isRendered();
+    }
+
+    public Object saveState(FacesContext context)
+    {
+        Object values[] = new Object[3];
+        values[0] = super.saveState(context);
+        values[1] = _enabledOnUserRole;
+        values[2] = _visibleOnUserRole;
+        return ((Object) (values));
+    }
+
+    public void restoreState(FacesContext context, Object state)
+    {
+        Object values[] = (Object[])state;
+        super.restoreState(context, values[0]);
+        _enabledOnUserRole = (String)values[1];
+        _visibleOnUserRole = (String)values[2];
+    }
+    //------------------ GENERATED CODE END ---------------------------------------
+}

Added: myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.xml
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.xml?rev=180077&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.xml (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/component/html/ext/HtmlGraphicImage.xml Sun Jun  5 03:18:07 2005
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE component PUBLIC
+  "-//MyFaces//DTD MyFaces component def 1.0//EN"
+  "http://myfaces.apache.org/dtd/Component.dtd">
+<component generateStateMethods="true" generateUserRoleMethods="true" >
+    <component-class>org.apache.myfaces.component.html.ext.HtmlGraphicImage</component-class>
+    <base-class>javax.faces.component.html.HtmlGraphicImage</base-class>
+    <component-type>org.apache.myfaces.HtmlGraphicImage</component-type>
+    <field>
+        <name>enabledOnUserRole</name>
+        <type>java.lang.String</type>
+    </field>
+    <field>
+        <name>visibleOnUserRole</name>
+        <type>java.lang.String</type>
+    </field>
+</component>

Added: myfaces/trunk/src/components/org/apache/myfaces/renderkit/html/ext/HtmlImageRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/renderkit/html/ext/HtmlImageRenderer.java?rev=180077&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/renderkit/html/ext/HtmlImageRenderer.java (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/renderkit/html/ext/HtmlImageRenderer.java Sun Jun  5 03:18:07 2005
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ * 
+ * Licensed 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.renderkit.html.ext;
+
+import org.apache.myfaces.renderkit.html.HtmlImageRendererBase;
+
+
+/**
+ * @author Martin Marinschek (latest modification by $Author: mmarinschek $)
+ * @author Bruno Aranda
+ * @version $Revision: 167446 $ $Date: 2004-12-23 13:03:09Z $
+ */
+public class HtmlImageRenderer
+    extends HtmlImageRendererBase
+{
+	
+	
+	
+}

Added: myfaces/trunk/src/components/org/apache/myfaces/taglib/html/ext/HtmlGraphicImageTag.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/components/org/apache/myfaces/taglib/html/ext/HtmlGraphicImageTag.java?rev=180077&view=auto
==============================================================================
--- myfaces/trunk/src/components/org/apache/myfaces/taglib/html/ext/HtmlGraphicImageTag.java (added)
+++ myfaces/trunk/src/components/org/apache/myfaces/taglib/html/ext/HtmlGraphicImageTag.java Sun Jun  5 03:18:07 2005
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.taglib.html.ext;
+
+import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.html.ext.HtmlGraphicImage;
+import org.apache.myfaces.taglib.html.HtmlGraphicImageTagBase;
+
+/**
+ * @author Bruno Aranda
+ * @version $Revision$ $Date: 2005-05-11 18:45:06 +0200 (Wed, 11 May 2005) $
+ */
+public class HtmlGraphicImageTag
+        extends HtmlGraphicImageTagBase
+{
+    public String getComponentType()
+    {
+        return HtmlGraphicImage.COMPONENT_TYPE;
+    }
+
+    public String getRendererType()
+    {
+        return "org.apache.myfaces.Image";
+    }
+
+    private String _enabledOnUserRole;
+    private String _visibleOnUserRole;
+
+    public void release() {
+        super.release();
+        _enabledOnUserRole=null;
+        _visibleOnUserRole=null;
+   }
+
+    protected void setProperties(UIComponent component)
+    {
+        super.setProperties(component);
+        setStringProperty(component, UserRoleAware.ENABLED_ON_USER_ROLE_ATTR, _enabledOnUserRole);
+        setStringProperty(component, UserRoleAware.VISIBLE_ON_USER_ROLE_ATTR, _visibleOnUserRole);
+    }
+
+    public void setEnabledOnUserRole(String enabledOnUserRole)
+    {
+        _enabledOnUserRole = enabledOnUserRole;
+    }
+
+    public void setVisibleOnUserRole(String visibleOnUserRole)
+    {
+        _visibleOnUserRole = visibleOnUserRole;
+    }
+
+}

Modified: myfaces/trunk/src/myfaces/org/apache/myfaces/application/ApplicationImpl.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/myfaces/org/apache/myfaces/application/ApplicationImpl.java?rev=180077&r1=180076&r2=180077&view=diff
==============================================================================
--- myfaces/trunk/src/myfaces/org/apache/myfaces/application/ApplicationImpl.java (original)
+++ myfaces/trunk/src/myfaces/org/apache/myfaces/application/ApplicationImpl.java Sun Jun  5 03:18:07 2005
@@ -447,7 +447,11 @@
 
         try
         {
-            return (Converter) converterClass.newInstance();
+            Converter converter= (Converter) converterClass.newInstance();
+
+            setConverterProperties(converterClass, converter);
+
+            return converter;
         }
         catch (Exception e)
         {
@@ -501,26 +505,7 @@
             {
                 Converter converter = (Converter) converterClass.newInstance();
 
-                org.apache.myfaces.config.impl.digester.elements.Converter converterConfig =
-                        (org.apache.myfaces.config.impl.digester.elements.Converter)
-                            _converterClassNameToConfigurationMap.get(converterClass.getName());
-
-                Iterator it = converterConfig.getProperties();
-
-                while (it.hasNext())
-                {
-                    Property property = (Property) it.next();
-
-                    try
-                    {
-                        BeanUtils.setProperty(converter,property.getPropertyName(),property.getDefaultValue());
-                    }
-                    catch(Throwable th)
-                    {
-                        log.error("Initializing converter : "+converterClass.getName()+" with property : "+
-                                property.getPropertyName()+" and value : "+property.getDefaultValue()+" failed.");
-                    }
-                }
+                setConverterProperties(converterClass, converter);
 
                 return converter;
             }
@@ -571,6 +556,34 @@
             return null;
         }
 
+    }
+
+    private void setConverterProperties(Class converterClass, Converter converter)
+    {
+        org.apache.myfaces.config.impl.digester.elements.Converter converterConfig =
+                (org.apache.myfaces.config.impl.digester.elements.Converter)
+                    _converterClassNameToConfigurationMap.get(converterClass.getName());
+
+        if(converterConfig != null)
+        {
+
+            Iterator it = converterConfig.getProperties();
+
+            while (it.hasNext())
+            {
+                Property property = (Property) it.next();
+
+                try
+                {
+                    BeanUtils.setProperty(converter,property.getPropertyName(),property.getDefaultValue());
+                }
+                catch(Throwable th)
+                {
+                    log.error("Initializing converter : "+converterClass.getName()+" with property : "+
+                            property.getPropertyName()+" and value : "+property.getDefaultValue()+" failed.");
+                }
+            }
+        }
     }
 
 

Modified: myfaces/trunk/src/myfaces/org/apache/myfaces/renderkit/html/HtmlImageRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/myfaces/org/apache/myfaces/renderkit/html/HtmlImageRenderer.java?rev=180077&r1=180076&r2=180077&view=diff
==============================================================================
--- myfaces/trunk/src/myfaces/org/apache/myfaces/renderkit/html/HtmlImageRenderer.java (original)
+++ myfaces/trunk/src/myfaces/org/apache/myfaces/renderkit/html/HtmlImageRenderer.java Sun Jun  5 03:18:07 2005
@@ -15,18 +15,6 @@
  */
 package org.apache.myfaces.renderkit.html;
 
-import org.apache.myfaces.renderkit.JSFAttr;
-import org.apache.myfaces.renderkit.RendererUtils;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import javax.faces.component.UIComponent;
-import javax.faces.component.UIGraphic;
-import javax.faces.component.html.HtmlGraphicImage;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
 
 
 /**
@@ -35,46 +23,7 @@
  * @version $Revision$ $Date$
  */
 public class HtmlImageRenderer
-extends HtmlRenderer
+extends HtmlImageRendererBase
 {
-    private static final Log log = LogFactory.getLog(HtmlImageRenderer.class);
-
-    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
-            throws IOException
-    {
-        RendererUtils.checkParamValidity(facesContext, uiComponent, UIGraphic.class);
-
-        ResponseWriter writer = facesContext.getResponseWriter();
-
-        String url;
-        if (uiComponent instanceof HtmlGraphicImage)
-        {
-            url = ((HtmlGraphicImage)uiComponent).getUrl();
-        }
-        else
-        {
-            url = (String)uiComponent.getAttributes().get(JSFAttr.URL_ATTR);
-        }
-
-        if ((url != null) && (url.length() > 0))
-        {
-            writer.startElement(HTML.IMG_ELEM, uiComponent);
-
-            writer.writeAttribute(HTML.ID_ATTR, uiComponent.getClientId(facesContext), null);
-
-            String src = facesContext.getApplication()
-                            .getViewHandler().getResourceURL(facesContext, url);
-            writer.writeURIAttribute(HTML.SRC_ATTR,
-                                     facesContext.getExternalContext().encodeResourceURL(src),
-                                     null);
-
-            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
-
-            writer.endElement(HTML.IMG_ELEM);
-        }
-        else
-        {
-            if (log.isWarnEnabled()) log.warn("Graphic with id " + uiComponent.getClientId(facesContext) + " has no value (url).");
-        }
-    }
+   
 }

Added: myfaces/trunk/src/share/org/apache/myfaces/renderkit/html/HtmlImageRendererBase.java
URL: http://svn.apache.org/viewcvs/myfaces/trunk/src/share/org/apache/myfaces/renderkit/html/HtmlImageRendererBase.java?rev=180077&view=auto
==============================================================================
--- myfaces/trunk/src/share/org/apache/myfaces/renderkit/html/HtmlImageRendererBase.java (added)
+++ myfaces/trunk/src/share/org/apache/myfaces/renderkit/html/HtmlImageRendererBase.java Sun Jun  5 03:18:07 2005
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2004 The Apache Software Foundation.
+ *
+ * Licensed 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.renderkit.html;
+
+import java.io.IOException;
+
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIGraphic;
+import javax.faces.component.html.HtmlGraphicImage;
+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.renderkit.JSFAttr;
+import org.apache.myfaces.renderkit.RendererUtils;
+
+
+/**
+ * @author Manfred Geiler (latest modification by $Author: grantsmith $)
+ * @author Thomas Spiegl
+ * @author Anton Koinov
+ * @version $Revision$ $Date: 2005-05-11 18:45:06 +0200 (Wed, 11 May 2005) $
+ */
+public class HtmlImageRendererBase
+        extends HtmlRenderer
+{
+	 private static final Log log = LogFactory.getLog(HtmlImageRendererBase.class);
+
+	    public void encodeEnd(FacesContext facesContext, UIComponent uiComponent)
+	            throws IOException
+	    {
+	        RendererUtils.checkParamValidity(facesContext, uiComponent, UIGraphic.class);
+
+	        ResponseWriter writer = facesContext.getResponseWriter();
+
+	        String url;
+	        if (uiComponent instanceof HtmlGraphicImage)
+	        {
+	            url = ((HtmlGraphicImage)uiComponent).getUrl();
+	        }
+	        else
+	        {
+	            url = (String)uiComponent.getAttributes().get(JSFAttr.URL_ATTR);
+	        }
+
+	        if ((url != null) && (url.length() > 0))
+	        {
+	            writer.startElement(HTML.IMG_ELEM, uiComponent);
+	            
+	            HtmlRendererUtils.writeIdIfNecessary(writer, uiComponent, facesContext);
+
+	            String src = facesContext.getApplication()
+	                            .getViewHandler().getResourceURL(facesContext, url);
+	            writer.writeURIAttribute(HTML.SRC_ATTR,
+	                                     facesContext.getExternalContext().encodeResourceURL(src),
+	                                     null);
+
+	            HtmlRendererUtils.renderHTMLAttributes(writer, uiComponent, HTML.IMG_PASSTHROUGH_ATTRIBUTES);
+
+	            writer.endElement(HTML.IMG_ELEM);
+	        }
+	        else
+	        {
+	            if (log.isWarnEnabled()) log.warn("Graphic with id " + uiComponent.getClientId(facesContext) + " has no value (url).");
+	        }
+	    }
+
+}

Modified: myfaces/trunk/tlds/myfaces_ext.tld
URL: http://svn.apache.org/viewcvs/myfaces/trunk/tlds/myfaces_ext.tld?rev=180077&r1=180076&r2=180077&view=diff
==============================================================================
--- myfaces/trunk/tlds/myfaces_ext.tld (original)
+++ myfaces/trunk/tlds/myfaces_ext.tld Sun Jun  5 03:18:07 2005
@@ -266,6 +266,22 @@
         &ext_forceId_attribute;
         &display_value_only_attributes;
     </tag>
+    
+     <!-- graphicImage -->
+    <tag>
+        <name>graphicImage</name>
+        <tag-class>org.apache.myfaces.taglib.html.ext.HtmlGraphicImageTag</tag-class>
+        <body-content>JSP</body-content>
+        <description>
+            Extends standard graphicImage.
+        </description>
+        &ui_graphic_attributes;
+        &html_universal_attributes;
+        &html_event_handler_attributes;
+        &html_img_attributes;
+        &user_role_attributes;
+        &ext_forceId_attribute;
+    </tag>
 
     <!-- message -->
     <tag>