in impl/src/main/java/org/apache/myfaces/view/facelets/tag/jstl/core/LegacyForEachHandler.java [130:292]
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
ELException
{
int s = this.getBegin(ctx);
int e = this.getEnd(ctx);
int m = this.getStep(ctx);
Integer sO = this.begin != null ? Integer.valueOf(s) : null;
Integer eO = this.end != null ? Integer.valueOf(e) : null;
Integer mO = this.step != null ? Integer.valueOf(m) : null;
boolean t = this.getTransient(ctx);
Object src = null;
ValueExpression srcVE = null;
if (this.items != null)
{
srcVE = this.items.getValueExpression(ctx, Object.class);
src = srcVE.getValue(ctx);
}
else
{
byte[] b = new byte[e + 1];
for (int i = 0; i < b.length; i++)
{
b[i] = (byte) i;
}
src = b;
}
FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
if (src != null)
{
try
{
fcc.startComponentUniqueIdSection();
AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
PageContext pctx = actx.getPageContext();
Iterator<?> itr = this.toIterator(src);
if (itr != null)
{
int i = 0;
// move to start
while (i < s && itr.hasNext())
{
itr.next();
i++;
}
String v = this.getVarName(ctx);
String vs = this.getVarStatusName(ctx);
ValueExpression ve = null;
ValueExpression vO = this.capture(v, pctx);
ValueExpression vsO = this.capture(vs, pctx);
int mi = 0;
Object value = null;
try
{
boolean first = true;
while (i <= e && itr.hasNext())
{
value = itr.next();
// set the var
if (v != null)
{
if (t || srcVE == null)
{
if (value == null)
{
pctx.getAttributes().put(v, null);
}
else
{
pctx.getAttributes().put(v,
ctx.getExpressionFactory().createValueExpression(
value, Object.class));
}
}
else
{
ve = this.getVarExpr(srcVE, src, value, i);
pctx.getAttributes().put(v, ve);
}
}
// set the varStatus
if (vs != null)
{
IterationStatus itrS = new IterationStatus(first, !itr.hasNext(), i, sO, eO, mO, value);
if (t || srcVE == null)
{
if (srcVE == null)
{
pctx.getAttributes().put(vs, null);
}
else
{
pctx.getAttributes().put(vs,
ctx.getExpressionFactory().createValueExpression(
itrS, Object.class));
}
}
else
{
ve = new IterationStatusExpression(itrS);
pctx.getAttributes().put(vs, ve);
}
}
// execute body
this.nextHandler.apply(ctx, parent);
// increment steps
mi = 1;
while (mi < m && itr.hasNext())
{
itr.next();
mi++;
i++;
}
i++;
first = false;
}
}
finally
{
//Remove them from PageContext
if (v != null)
{
pctx.getAttributes().put(v, vO);
}
else
{
pctx.getAttributes().remove(v);
}
if (vs != null)
{
pctx.getAttributes().put(vs, vsO);
}
else
{
pctx.getAttributes().remove(vs);
}
}
}
}
finally
{
fcc.endComponentUniqueIdSection();
}
}
if (fcc.isUsingPSSOnThisView() && fcc.isRefreshTransientBuildOnPSS() && !fcc.isRefreshingTransientBuild())
{
//Mark the parent component to be saved and restored fully.
ComponentSupport.markComponentToRestoreFully(ctx.getFacesContext(), parent);
}
if (fcc.isDynamicComponentSection())
{
ComponentSupport.markComponentToRefreshDynamically(ctx.getFacesContext(), parent);
}
}