myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bara...@apache.org
Subject svn commit: r227083 - in /myfaces: examples/trunk/simple/ tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/ tomahawk/trunk/tld/
Date Tue, 02 Aug 2005 21:07:34 GMT
Author: baranda
Date: Tue Aug  2 14:07:03 2005
New Revision: 227083

URL: http://svn.apache.org/viewcvs?rev=227083&view=rev
Log:
Added rendered and user role attributes to the htmlTag component (and to its div subcomponent,
which extends from it). Also reformatted the classes with the myfaces code style.

Modified:
    myfaces/examples/trunk/simple/htmlTag.jsp
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTag.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java
    myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagTag.java
    myfaces/tomahawk/trunk/tld/myfaces_ext.tld

Modified: myfaces/examples/trunk/simple/htmlTag.jsp
URL: http://svn.apache.org/viewcvs/myfaces/examples/trunk/simple/htmlTag.jsp?rev=227083&r1=227082&r2=227083&view=diff
==============================================================================
--- myfaces/examples/trunk/simple/htmlTag.jsp (original)
+++ myfaces/examples/trunk/simple/htmlTag.jsp Tue Aug  2 14:07:03 2005
@@ -33,6 +33,12 @@
     <x:htmlTag value="p"><b>p</b> tag.</x:htmlTag>
     <x:htmlTag value="i"><b>i</b> tag.</x:htmlTag>
 
+	<x:htmlTag value="p">
+    	<x:htmlTag value="b" rendered="true">This is bold, because the <i>b</i>
tag is rendered</x:htmlTag>
+    </x:htmlTag>
+    <x:htmlTag value="p">
+    	<x:htmlTag value="b" rendered="false">This should be bold, but the <i>b</i>
tag is not rendered</x:htmlTag>
+    </x:htmlTag>
 </f:view>
 
 <%@include file="inc/page_footer.jsp" %>

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTag.java?rev=227083&r1=227082&r2=227083&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTag.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTag.java Tue Aug
 2 14:07:03 2005
@@ -19,73 +19,124 @@
 import javax.faces.context.FacesContext;
 import javax.faces.el.ValueBinding;
 
+import org.apache.myfaces.component.DisplayValueOnlyCapable;
+import org.apache.myfaces.component.UserRoleAware;
+import org.apache.myfaces.component.UserRoleUtils;
 import org.apache.myfaces.component.html.util.HtmlComponentUtils;
 
 /**
  * @author bdudney (latest modification by $Author$)
  * @version $Revision$ $Date: 2005-05-11 11:47:12 -0400 (Wed, 11 May 2005) $
  */
-public class HtmlTag extends UIOutput {
-  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 = HtmlTagRenderer.RENDERER_TYPE;
-
-  private String _style = null;
-  private String _styleClass = null;
-
-  public HtmlTag() {
-    setRendererType(DEFAULT_RENDERER_TYPE);
-  }
-
-  public String getFamily() {
-    return COMPONENT_FAMILY;
-  }
-
-  public String getClientId(FacesContext context)
-  {
-      String clientId = HtmlComponentUtils.getClientId(this, getRenderer(context), context);
-      if (clientId == null)
-      {
-          clientId = super.getClientId(context);
-      }
-
-      return clientId;
-    }
-
-  public String getStyle() {
-    if (_style != null)
-      return _style;
-    ValueBinding vb = getValueBinding("style");
-    return vb != null ? (String) vb.getValue(getFacesContext()) : null;
-  }
-
-  public void setStyle(String style) {
-    this._style = style;
-  }
-
-  public String getStyleClass() {
-    if (_styleClass != null)
-      return _styleClass;
-    ValueBinding vb = getValueBinding("styleClass");
-    return vb != null ? (String) vb.getValue(getFacesContext()) : null;
-  }
-
-  public void setStyleClass(String styleClass) {
-    this._styleClass = styleClass;
-  }
-
-  public void restoreState(FacesContext context, Object state) {
-    Object values[] = (Object[]) state;
-    super.restoreState(context, values[0]);
-    _style = (String) values[1];
-    _styleClass = (String) values[2];
-  }
-
-  public Object saveState(FacesContext context) {
-    Object values[] = new Object[3];
-    values[0] = super.saveState(context);
-    values[1] = _style;
-    values[2] = _styleClass;
-    return values;
-  }
+public class HtmlTag extends UIOutput implements UserRoleAware
+{
+
+    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 = HtmlTagRenderer.RENDERER_TYPE;
+
+    private String _style = null;
+    private String _styleClass = null;
+    private String _enabledOnUserRole = null;
+    private String _visibleOnUserRole = null;
+
+    public HtmlTag()
+    {
+        setRendererType(DEFAULT_RENDERER_TYPE);
+    }
+
+    public String getFamily()
+    {
+        return COMPONENT_FAMILY;
+    }
+
+    public String getClientId(FacesContext context)
+    {
+        String clientId = HtmlComponentUtils.getClientId(this,
+                getRenderer(context), context);
+        if (clientId == null)
+        {
+            clientId = super.getClientId(context);
+        }
+
+        return clientId;
+    }
+
+    public String getStyle()
+    {
+        if (_style != null)
+            return _style;
+        ValueBinding vb = getValueBinding("style");
+        return vb != null ? (String) vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setStyle(String style)
+    {
+        this._style = style;
+    }
+
+    public String getStyleClass()
+    {
+        if (_styleClass != null)
+            return _styleClass;
+        ValueBinding vb = getValueBinding("styleClass");
+        return vb != null ? (String) vb.getValue(getFacesContext()) : null;
+    }
+
+    public void setStyleClass(String styleClass)
+    {
+        this._styleClass = styleClass;
+    }
+
+    public void restoreState(FacesContext context, Object state)
+    {
+        Object values[] = (Object[]) state;
+        super.restoreState(context, values[0]);
+        _style = (String) values[1];
+        _styleClass = (String) values[2];
+        _enabledOnUserRole = (String) values[3];
+        _visibleOnUserRole = (String) values[4];
+    }
+
+    public Object saveState(FacesContext context)
+    {
+        Object values[] = new Object[5];
+        values[0] = super.saveState(context);
+        values[1] = _style;
+        values[2] = _styleClass;
+        values[3] = _enabledOnUserRole;
+        values[4] = _visibleOnUserRole;
+        return values;
+    }
+
+    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();
+    }
+
 }

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java?rev=227083&r1=227082&r2=227083&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java
(original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagRenderer.java
Tue Aug  2 14:07:03 2005
@@ -21,45 +21,62 @@
 import javax.faces.context.FacesContext;
 import javax.faces.context.ResponseWriter;
 
+import org.apache.myfaces.component.UserRoleUtils;
 import org.apache.myfaces.renderkit.html.HTML;
 import org.apache.myfaces.renderkit.html.HtmlRenderer;
 import org.apache.myfaces.renderkit.html.HtmlRendererUtils;
+
 /**
  * @author bdudney (latest modification by $Author$)
  * @version $Revision$ $Date: 2005-05-11 11:47:12 -0400 (Wed, 11 May 2005) $
  */
-public class HtmlTagRenderer extends HtmlRenderer {
-  public static final String RENDERER_TYPE = "org.apache.myfaces.HtmlTagRenderer";
+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;
-    ResponseWriter writer = context.getResponseWriter();
+    public void encodeBegin(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        if ((context == null) || (component == null))
+        {
+            throw new NullPointerException();
+        }
+        HtmlTag htmlTag = (HtmlTag) component;
 
-    writer.startElement(htmlTag.getValue().toString(), htmlTag);
-    HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
+        if (htmlTag.isRendered())
+        {
+            ResponseWriter writer = context.getResponseWriter();
 
-    String styleClass = htmlTag.getStyleClass();
-    String style = htmlTag.getStyle();
+            writer.startElement(htmlTag.getValue().toString(), htmlTag);
+            HtmlRendererUtils.writeIdIfNecessary(writer, component, context);
 
-    if(null != styleClass) {
-        writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
-    }
-    if(null != style) {
-        writer.writeAttribute(HTML.STYLE_ATTR, style, null);
+            String styleClass = htmlTag.getStyleClass();
+            String style = htmlTag.getStyle();
+
+            if (null != styleClass)
+            {
+                writer.writeAttribute(HTML.CLASS_ATTR, styleClass, null);
+            }
+            if (null != style)
+            {
+                writer.writeAttribute(HTML.STYLE_ATTR, style, null);
+            }
+        }  
     }
-  }
 
-  public void encodeEnd(FacesContext context, UIComponent component)
-      throws IOException {
-    if ((context == null) || (component == null)) {
-      throw new NullPointerException();
+    public void encodeEnd(FacesContext context, UIComponent component)
+            throws IOException
+    {
+        if ((context == null) || (component == null))
+        {
+            throw new NullPointerException();
+        }
+        HtmlTag htmlTag = (HtmlTag) component;
+
+        if (htmlTag.isRendered())
+        {
+            ResponseWriter writer = context.getResponseWriter();
+            writer.endElement(htmlTag.getValue().toString());
+        }
     }
-    HtmlTag htmlTag = (HtmlTag) component;
-    ResponseWriter writer = context.getResponseWriter();
-    writer.endElement(htmlTag.getValue().toString());
-  }
 }

Modified: myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagTag.java
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagTag.java?rev=227083&r1=227082&r2=227083&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagTag.java (original)
+++ myfaces/tomahawk/trunk/src/java/org/apache/myfaces/custom/htmlTag/HtmlTagTag.java Tue
Aug  2 14:07:03 2005
@@ -16,6 +16,8 @@
 package org.apache.myfaces.custom.htmlTag;
 
 import javax.faces.component.UIComponent;
+
+import org.apache.myfaces.component.UserRoleAware;
 import org.apache.myfaces.taglib.html.HtmlOutputTextTagBase;
 /**
  * @author bdudney (latest modification by $Author$)
@@ -24,6 +26,8 @@
 public class HtmlTagTag extends HtmlOutputTextTagBase {
   private String _style = null;
   private String _styleClass = null;
+  private String _enabledOnUserRole;
+  private String _visibleOnUserRole;
 
   public String getComponentType() {
     return HtmlTag.COMPONENT_TYPE;
@@ -37,6 +41,8 @@
     super.release();
     this._style = null;
     this._styleClass = null;
+    this._enabledOnUserRole=null;
+    this._visibleOnUserRole=null;
   }
 
   /**
@@ -46,6 +52,8 @@
     super.setProperties(component);
     setStringProperty(component, "style", _style);
     setStringProperty(component, "styleClass", _styleClass);
+    setStringProperty(component, UserRoleAware.ENABLED_ON_USER_ROLE_ATTR, _enabledOnUserRole);
+    setStringProperty(component, UserRoleAware.VISIBLE_ON_USER_ROLE_ATTR, _visibleOnUserRole);
   }
 
   public void setStyle(String style) {
@@ -54,5 +62,15 @@
 
   public void setStyleClass(String styleClass) {
     this._styleClass = styleClass;
+  }
+  
+  public void setEnabledOnUserRole(String enabledOnUserRole)
+  {
+      _enabledOnUserRole = enabledOnUserRole;
+  }
+
+  public void setVisibleOnUserRole(String visibleOnUserRole)
+  {
+      _visibleOnUserRole = visibleOnUserRole;
   }
 }

Modified: myfaces/tomahawk/trunk/tld/myfaces_ext.tld
URL: http://svn.apache.org/viewcvs/myfaces/tomahawk/trunk/tld/myfaces_ext.tld?rev=227083&r1=227082&r2=227083&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/tld/myfaces_ext.tld (original)
+++ myfaces/tomahawk/trunk/tld/myfaces_ext.tld Tue Aug  2 14:07:03 2005
@@ -1760,6 +1760,7 @@
 		<description>Places a div around its children</description>
 		&ui_component_attributes;
         &ext_forceId_attribute;
+        &user_role_attributes;
 		<attribute>
 			<name>style</name>
 			<required>false</required>
@@ -1787,6 +1788,7 @@
 		<description>Places the given HTML tag div around its children</description>
 		&ui_component_attributes;
         &ext_forceId_attribute;
+        &user_role_attributes;
         <attribute>
             <name>value</name>
             <required>true</required>



Mime
View raw message