You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-commits@incubator.apache.org by aw...@apache.org on 2007/02/03 00:10:01 UTC

svn commit: r502802 - in /incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main: conf/META-INF/tr-base.tld java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java

Author: awiner
Date: Fri Feb  2 16:10:00 2007
New Revision: 502802

URL: http://svn.apache.org/viewvc?view=rev&rev=502802
Log:
JSF 1.2: fix tr:forEach to support EL for begin, end, and step

Modified:
    incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld
    incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java

Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld?view=diff&rev=502802&r1=502801&r2=502802
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld (original)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/conf/META-INF/tr-base.tld Fri Feb  2 16:10:00 2007
@@ -1,249 +1,255 @@
-<?xml version = "1.0" ?>
-<!--
-    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.
-	   
--->
+<?xml version = "1.0" ?>
+<!--
+    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.
+	   
+-->
 <taglib
   xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
   version="2.1">
 
-  <display-name>Apache Trinidad Core</display-name>    
-  <tlib-version>11-m3</tlib-version>
-  <short-name>tr</short-name>
-  <uri>http://myfaces.apache.org/trinidad</uri>
-  <listener>
-    <listener-class>org.apache.myfaces.trinidadinternal.webapp.TrinidadListenerImpl</listener-class>
-  </listener>
-        
-   <tag>
-      <description>
+  <display-name>Apache Trinidad Core</display-name>    
+  <tlib-version>11-m3</tlib-version>
+  <short-name>tr</short-name>
+  <uri>http://myfaces.apache.org/trinidad</uri>
+  <listener>
+    <listener-class>org.apache.myfaces.trinidadinternal.webapp.TrinidadListenerImpl</listener-class>
+  </listener>
+        
+   <tag>
+      <description>
 The forEach tag is a replacement for the JSTL &amp;lt;c:forEach&amp;gt; tag. 
 As of JSF 1.2/JSP 2.1/JSTL 1.2, the regular &amp;lt;c:forEach&amp;gt; tag
 does work with JSF components.  However, it does not support varStatus
 with JSF!  (Unlike c:forEach, tr:forEach doesn't currently support anything
 for "items" other than arrays and lists.)
-      </description>
-      <name>forEach</name>
-      <tag-class>org.apache.myfaces.trinidadinternal.taglib.ForEachTag</tag-class>
-      <body-content>jsp</body-content>
-
-      <attribute>
-        <description>
-          the items over which iteration takes place 
-        </description>
-        <name>items</name>
-        <deferred-value/>
-      </attribute>
-
-      <attribute>
-        <description>
-          the name of the variable to expose
-        </description>
-        <name>var</name>
-        <rtexprvalue>false</rtexprvalue>
-      </attribute>
-
-      <attribute>
-        <description>
-          Name of the exported scoped variable for the
-          status of the iteration.
-        </description>
-        <name>varStatus</name>
-        <rtexprvalue>false</rtexprvalue>
-      </attribute>
-
-      <attribute>
-        <description>
-          the beginning index 
-        </description>
-        <name>begin</name>
-        <rtexprvalue>false</rtexprvalue>
-      </attribute>
-
-      <attribute>
-        <description>
-          the ending index 
-        </description>
-        <name>end</name>
-        <rtexprvalue>false</rtexprvalue>
-      </attribute>
-
-      <attribute>
-        <description>
-          the number of steps per iteration
-        </description>
-        <name>step</name>
-        <rtexprvalue>false</rtexprvalue>
-      </attribute>
-
-   </tag>
-
-   <tag>
-      <description>
-        The setActionListener tag provides a declarative syntax for assigning values before an action fires
-      </description>
-
-      <name>setActionListener</name>
-      <tag-class>org.apache.myfaces.trinidadinternal.taglib.listener.SetActionListenerTag</tag-class>
-      <body-content>empty</body-content>
-      <attribute>
-        <description>
-          the target for the value;  must be an EL expression
-        </description>
-        <name>to</name>
-        <required>true</required>
-        <deferred-value/>
-      </attribute>
-
-      <attribute>
-        <description>
-          the source of the value;  can be an EL expression or a constant value
-        </description>
-        <name>from</name>
-        <required>true</required>
-        <deferred-value/>
-      </attribute>
-   </tag>
-
-   <tag>
-      <description>
-        The returnActionListener tag is a declarative way to allow an action source to return 
-        a value from a dialog or process.
-      </description>
-      <name>returnActionListener</name>
-      <tag-class>org.apache.myfaces.trinidadinternal.taglib.listener.ReturnActionListenerTag</tag-class>
-      <body-content>empty</body-content>
-
-      <attribute>
-        <description>
-          The value to return as the dialog/process result.
-          This can be an EL expression or a constant value.
-        </description>
-        <name>value</name>
-        <deferred-value/>
-      </attribute>
-   </tag>
-
-
-   <tag>
-      <description>
-        The resetActionListener tag provides a declarative syntax for resetting values before an action fires
-      </description>
-      <name>resetActionListener</name>
-      <tag-class>org.apache.myfaces.trinidadinternal.taglib.listener.ResetActionListenerTag</tag-class>
-      <body-content>empty</body-content>
-   </tag>
- 
-   <tag>
-      <description> 
-
-      The componentRef tag adds declarative components onto the current
-      component tree. The declarative component is usually defined in a jsp
-      file.  It is currently experimental and should not be used by
-      developers.
-
-      </description>
-
-      <name>componentRef</name>
-      <tag-class>org.apache.myfaces.trinidadinternal.taglib.ComponentRefTag</tag-class>
-      <body-content>jsp</body-content>
-      <attribute>
-        <description>
-Identifies which declarative component to use. 
-All the available components must be
-declared in a region-metadata.xml file.
-        </description>
-        <name>componentType</name>
-        <required>true</required>
-        <deferred-value/>
-      </attribute>
-
-      <attribute>
-        <description>
-          This ID must be unique within this page. 
-        </description>
-        <name>id</name>
-        <required>true</required>
-      </attribute>
-
-      <attribute>
-        <description>
-          A value to pass to the component definition.
-        </description>
-        <name>value</name>
-        <required>false</required>
-        <deferred-value/>
-      </attribute>
-
-      <attribute>
-        <description>
-          Whether or not this component is rendered.
-        </description>
-        <name>rendered</name>
-        <required>false</required>
-        <deferred-value/>
-      </attribute>
-
-   </tag>
-
-
-    <tag>
-      <description>
-        The componentDef tag is used to define a component. Its primary purpose
-is defining a "var" property so that the definition can refer to attributes
-on this component's usage.
-      </description>
-      <name>componentDef</name>   
-      <tag-class>org.apache.myfaces.trinidadinternal.taglib.ComponentDefTag</tag-class>
-      <body-content>jsp</body-content>
-      <attribute>
-        <description>
-          the variable name to use when referencing attributes, that may be set
-          on this new component.
-        </description>
-        <name>var</name>
-        <rtexprvalue>false</rtexprvalue>
-      </attribute>
-    </tag>        
-
-
-    <tag>
-      <description>
-        The facetRef tag is used to copy facets from a component
-        and paste them into its
-        definition. This tag may only be used within an &lt;tr:componentDef&gt;
-        tag.
-        Each facet may be used only once within each 
-        &lt;tr:componentDef&gt;. In other words, a single facet cannot be
-        used more than once.
-      </description>
-      <name>facetRef</name>   
-      <tag-class>org.apache.myfaces.trinidadinternal.taglib.FacetRefTag</tag-class>
-      <body-content>jsp</body-content>
-      <attribute>
-        <description>
-          the facet name to copy
-        </description>
-        <name>facetName</name>
-        <rtexprvalue>false</rtexprvalue>
-      </attribute>
-    </tag>        
-
-</taglib>
+      </description>
+      <name>forEach</name>
+      <tag-class>org.apache.myfaces.trinidadinternal.taglib.ForEachTag</tag-class>
+      <body-content>jsp</body-content>
+
+      <attribute>
+        <description>
+          the items over which iteration takes place 
+        </description>
+        <name>items</name>
+        <deferred-value/>
+      </attribute>
+
+      <attribute>
+        <description>
+          the name of the variable to expose
+        </description>
+        <name>var</name>
+        <rtexprvalue>false</rtexprvalue>
+      </attribute>
+
+      <attribute>
+        <description>
+          Name of the exported scoped variable for the
+          status of the iteration.
+        </description>
+        <name>varStatus</name>
+        <rtexprvalue>false</rtexprvalue>
+      </attribute>
+
+      <attribute>
+        <description>
+          the beginning index 
+        </description>
+        <name>begin</name>
+        <deferred-value>
+          <type>java.lang.Integer</type>
+        </deferred-value>
+      </attribute>
+
+      <attribute>
+        <description>
+          the ending index 
+        </description>
+        <name>end</name>
+        <deferred-value>
+          <type>java.lang.Integer</type>
+        </deferred-value>
+      </attribute>
+
+      <attribute>
+        <description>
+          the number of steps per iteration
+        </description>
+        <name>step</name>
+        <deferred-value>
+          <type>java.lang.Integer</type>
+        </deferred-value>
+      </attribute>
+
+   </tag>
+
+   <tag>
+      <description>
+        The setActionListener tag provides a declarative syntax for assigning values before an action fires
+      </description>
+
+      <name>setActionListener</name>
+      <tag-class>org.apache.myfaces.trinidadinternal.taglib.listener.SetActionListenerTag</tag-class>
+      <body-content>empty</body-content>
+      <attribute>
+        <description>
+          the target for the value;  must be an EL expression
+        </description>
+        <name>to</name>
+        <required>true</required>
+        <deferred-value/>
+      </attribute>
+
+      <attribute>
+        <description>
+          the source of the value;  can be an EL expression or a constant value
+        </description>
+        <name>from</name>
+        <required>true</required>
+        <deferred-value/>
+      </attribute>
+   </tag>
+
+   <tag>
+      <description>
+        The returnActionListener tag is a declarative way to allow an action source to return 
+        a value from a dialog or process.
+      </description>
+      <name>returnActionListener</name>
+      <tag-class>org.apache.myfaces.trinidadinternal.taglib.listener.ReturnActionListenerTag</tag-class>
+      <body-content>empty</body-content>
+
+      <attribute>
+        <description>
+          The value to return as the dialog/process result.
+          This can be an EL expression or a constant value.
+        </description>
+        <name>value</name>
+        <deferred-value/>
+      </attribute>
+   </tag>
+
+
+   <tag>
+      <description>
+        The resetActionListener tag provides a declarative syntax for resetting values before an action fires
+      </description>
+      <name>resetActionListener</name>
+      <tag-class>org.apache.myfaces.trinidadinternal.taglib.listener.ResetActionListenerTag</tag-class>
+      <body-content>empty</body-content>
+   </tag>
+ 
+   <tag>
+      <description> 
+
+      The componentRef tag adds declarative components onto the current
+      component tree. The declarative component is usually defined in a jsp
+      file.  It is currently experimental and should not be used by
+      developers.
+
+      </description>
+
+      <name>componentRef</name>
+      <tag-class>org.apache.myfaces.trinidadinternal.taglib.ComponentRefTag</tag-class>
+      <body-content>jsp</body-content>
+      <attribute>
+        <description>
+Identifies which declarative component to use. 
+All the available components must be
+declared in a region-metadata.xml file.
+        </description>
+        <name>componentType</name>
+        <required>true</required>
+        <deferred-value/>
+      </attribute>
+
+      <attribute>
+        <description>
+          This ID must be unique within this page. 
+        </description>
+        <name>id</name>
+        <required>true</required>
+      </attribute>
+
+      <attribute>
+        <description>
+          A value to pass to the component definition.
+        </description>
+        <name>value</name>
+        <required>false</required>
+        <deferred-value/>
+      </attribute>
+
+      <attribute>
+        <description>
+          Whether or not this component is rendered.
+        </description>
+        <name>rendered</name>
+        <required>false</required>
+        <deferred-value/>
+      </attribute>
+
+   </tag>
+
+
+    <tag>
+      <description>
+        The componentDef tag is used to define a component. Its primary purpose
+is defining a "var" property so that the definition can refer to attributes
+on this component's usage.
+      </description>
+      <name>componentDef</name>   
+      <tag-class>org.apache.myfaces.trinidadinternal.taglib.ComponentDefTag</tag-class>
+      <body-content>jsp</body-content>
+      <attribute>
+        <description>
+          the variable name to use when referencing attributes, that may be set
+          on this new component.
+        </description>
+        <name>var</name>
+        <rtexprvalue>false</rtexprvalue>
+      </attribute>
+    </tag>        
+
+
+    <tag>
+      <description>
+        The facetRef tag is used to copy facets from a component
+        and paste them into its
+        definition. This tag may only be used within an &lt;tr:componentDef&gt;
+        tag.
+        Each facet may be used only once within each 
+        &lt;tr:componentDef&gt;. In other words, a single facet cannot be
+        used more than once.
+      </description>
+      <name>facetRef</name>   
+      <tag-class>org.apache.myfaces.trinidadinternal.taglib.FacetRefTag</tag-class>
+      <body-content>jsp</body-content>
+      <attribute>
+        <description>
+          the facet name to copy
+        </description>
+        <name>facetName</name>
+        <rtexprvalue>false</rtexprvalue>
+      </attribute>
+    </tag>        
+
+</taglib>

Modified: incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java
URL: http://svn.apache.org/viewvc/incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java?view=diff&rev=502802&r1=502801&r2=502802
==============================================================================
--- incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java (original)
+++ incubator/adffaces/branches/faces-1_2-070201/trinidad/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/taglib/ForEachTag.java Fri Feb  2 16:10:00 2007
@@ -72,19 +72,19 @@
     _items = items;
   }
 
-  public void setBegin(Integer begin)
+  public void setBegin(ValueExpression begin)
   {
-    _begin = begin;
+    _beginVE = begin;
   }
 
-  public void setEnd(Integer end)
+  public void setEnd(ValueExpression end)
   {
-    _end = end;
+    _endVE = end;
   }
 
-  public void setStep(Integer step)
+  public void setStep(ValueExpression step)
   {
-    _step = step;
+    _stepVE = step;
   }
 
   public void setVar(String var)
@@ -302,8 +302,31 @@
     }
   }
 
+  private Integer _evaluateInteger(
+    FacesContext context,
+    ValueExpression ve)
+  {
+    if (ve == null)
+      return null;
+
+    Object val = ve.getValue(context.getELContext());
+    if (val instanceof Integer)
+      return (Integer) val;
+    else if (val instanceof Number)
+      return new Integer(((Number) val).intValue());
+    return null;
+  }
+
   private void _validateAttributes() throws JspTagException
   {
+    // Evaluate these three ValueExpressions into integers
+    // For why we use FacesContext instead of PageContext, see
+    // above (the evaluation of _items)
+    FacesContext context = FacesContext.getCurrentInstance();
+    _end = _evaluateInteger(context, _endVE);
+    _begin = _evaluateInteger(context, _beginVE);
+    _step = _evaluateInteger(context, _stepVE);
+
     if (null == _items)
     {
       if (null == _begin || null == _end)
@@ -397,9 +420,14 @@
   private ValueExpression _items;
   private Object          _itemsValue;
 
+  private ValueExpression _beginVE;
+  private ValueExpression _endVE;
+  private ValueExpression _stepVE;
+
   private Integer _begin;
   private Integer _end;
   private Integer _step;
+
   private String _var;
   private String _varStatus;