Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 // Copyright 2004, 2005 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
 // Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.tapestry.script;
import  org.apache.hivemind.Location;

A looping operator, modeled after the Foreach component. It takes as its source as property and iterates through the values, updating a symbol on each pass.

As of 3.0, the index attribute has been added to foreach to keep track of the current index of the iterating collection.

Howard Lewis Ship, Harish Krishnaswamy
class ForeachToken extends AbstractToken
    private String _key;
    private String _index;
    private String _expression;
    ForeachToken(String keyString indexString expression, Location location)
         = key;
         = index;
         = expression;
    public void write(StringBuffer bufferScriptSession session)
        Iterator i = (Iteratorsession.evaluate(Iterator.class);
        if (i == nullreturn;
        Map symbols = session.getSymbols();
        int index = 0;
            Object newValue =;
            if ( != nullsymbols.put(, String.valueOf(index));
        // We leave the last value as a symbol; don't know if that's
        // good or bad.
New to GrepCode? Check out our FAQ X