martinc 01/06/13 21:24:28 Modified: doc Tag: STRUTS_1_0_BRANCH struts-logic.xml src/share/org/apache/struts/taglib/logic Tag: STRUTS_1_0_BRANCH IterateTag.java IterateTei.java Log: Add a new attribute, 'indexId', which is used to expose the current index, at each iteration, as a scripting variable. The attribute names the desired scripting variable. Revision Changes Path No revision No revision 1.6.2.1 +10 -0 jakarta-struts/doc/struts-logic.xml Index: struts-logic.xml =================================================================== RCS file: /home/cvs/jakarta-struts/doc/struts-logic.xml,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -r1.6 -r1.6.2.1 --- struts-logic.xml 2001/05/09 19:31:02 1.6 +++ struts-logic.xml 2001/06/14 04:24:26 1.6.2.1 @@ -465,6 +465,16 @@ </attribute> <attribute> + <name>indexId</name> + <required>false</required> + <rtexprvalue>true</rtexprvalue> + <info> + <p>The name of a page scope JSP bean that will contain the current + index of the collection on each iteration.</p> + </info> + </attribute> + + <attribute> <name>length</name> <required>false</required> <rtexprvalue>true</rtexprvalue> No revision No revision 1.11.2.1 +22 -4 jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java Index: IterateTag.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java,v retrieving revision 1.11 retrieving revision 1.11.2.1 diff -u -r1.11 -r1.11.2.1 --- IterateTag.java 2001/04/29 01:26:19 1.11 +++ IterateTag.java 2001/06/14 04:24:27 1.11.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java,v 1.11 2001/04/29 01:26:19 craigmcc Exp $ - * $Revision: 1.11 $ - * $Date: 2001/04/29 01:26:19 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTag.java,v 1.11.2.1 2001/06/14 04:24:27 martinc Exp $ + * $Revision: 1.11.2.1 $ + * $Date: 2001/06/14 04:24:27 $ * * ==================================================================== * @@ -88,7 +88,7 @@ * or a Map (which includes Hashtables) whose elements will be iterated over. * * @author Craig R. McClanahan - * @version $Revision: 1.11 $ $Date: 2001/04/29 01:26:19 $ + * @version $Revision: 1.11.2.1 $ $Date: 2001/06/14 04:24:27 $ */ public class IterateTag extends BodyTagSupport { @@ -188,6 +188,20 @@ /** + * The name of the scripting variable to be exposed as the current index. + */ + protected String indexId = null; + + public String getIndexId() { + return (this.indexId); + } + + public void setIndexId(String indexId) { + this.indexId = indexId; + } + + + /** * The length value or attribute name (<=0 means no limit). */ protected String length = null; @@ -366,6 +380,8 @@ pageContext.setAttribute(id, element); lengthCount++; started = true; + if (indexId != null) + pageContext.setAttribute(indexId, new Integer(getIndex())); return (EVAL_BODY_TAG); } else return (SKIP_BODY); @@ -397,6 +413,8 @@ else pageContext.setAttribute(id, element); lengthCount++; + if (indexId != null) + pageContext.setAttribute(indexId, new Integer(getIndex())); return (EVAL_BODY_TAG); } else return (SKIP_BODY); 1.4.2.1 +24 -11 jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTei.java Index: IterateTei.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTei.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -r1.4 -r1.4.2.1 --- IterateTei.java 2001/02/12 21:49:56 1.4 +++ IterateTei.java 2001/06/14 04:24:27 1.4.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTei.java,v 1.4 2001/02/12 21:49:56 craigmcc Exp $ - * $Revision: 1.4 $ - * $Date: 2001/02/12 21:49:56 $ + * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/logic/IterateTei.java,v 1.4.2.1 2001/06/14 04:24:27 martinc Exp $ + * $Revision: 1.4.2.1 $ + * $Date: 2001/06/14 04:24:27 $ * * ==================================================================== * @@ -73,7 +73,7 @@ * tag, identifying the scripting object(s) to be made visible. * * @author Craig R. McClanahan - * @version $Revision: 1.4 $ $Date: 2001/02/12 21:49:56 $ + * @version $Revision: 1.4.2.1 $ $Date: 2001/06/14 04:24:27 $ */ public class IterateTei extends TagExtraInfo { @@ -87,13 +87,26 @@ String type = data.getAttributeString("type"); if (type == null) type = "java.lang.Object"; - - return new VariableInfo[] { - new VariableInfo(data.getAttributeString("id"), - type, - true, - VariableInfo.NESTED) - }; + VariableInfo typeInfo = new VariableInfo( + data.getAttributeString("id"), + type, + true, + VariableInfo.NESTED); + + String indexId = data.getAttributeString("indexId"); + VariableInfo indexIdInfo = null; + if (indexId != null) + indexIdInfo = new VariableInfo( + indexId, + "java.lang.Integer", + true, + VariableInfo.NESTED); + + if (indexIdInfo == null) { + return new VariableInfo[] { typeInfo }; + } else { + return new VariableInfo[] { typeInfo, indexIdInfo }; + } }