if (beforePhase)
{
// process listeners in ascending order
for (int i = 0; i < beforePhaseSuccess.length - 1; i++)
{
PhaseListener phaseListener;
try
{
phaseListener = phaseListeners.get(i);
}
catch (IndexOutOfBoundsException e)
{
// happens when a PhaseListener removes another PhaseListener
// from UIViewRoot in its beforePhase method
throw new IllegalStateException("A PhaseListener must not remove " +
"PhaseListeners from UIViewRoot.");
}
PhaseId listenerPhaseId = phaseListener.getPhaseId();
if (phaseId.equals(listenerPhaseId) || PhaseId.ANY_PHASE.equals(listenerPhaseId))
{
try
{
phaseListener.beforePhase(event);
beforePhaseSuccess[i + 1] = true;
}
catch (Throwable t)
{
beforePhaseSuccess[i + 1] = false; // redundant - for clarity
logger.log(Level.SEVERE, "An Exception occured while processing the " +
"beforePhase method of PhaseListener " + phaseListener +
" in Phase " + phaseId, t);
return context.getResponseComplete() ||
(context.getRenderResponse() && !PhaseId.RENDER_RESPONSE.equals(phaseId));
}
}
}
}
else
{
// afterPhase
// process listeners in descending order
for (int i = beforePhaseSuccess.length - 1; i > 0; i--)
{
PhaseListener phaseListener;
try
{
phaseListener = phaseListeners.get(i - 1);
}
catch (IndexOutOfBoundsException e)
{
// happens when a PhaseListener removes another PhaseListener
// from UIViewRoot in its beforePhase or afterPhase method
throw new IllegalStateException("A PhaseListener must not remove " +
"PhaseListeners from UIViewRoot.");
}
PhaseId listenerPhaseId = phaseListener.getPhaseId();
if ((phaseId.equals(listenerPhaseId) || PhaseId.ANY_PHASE.equals(listenerPhaseId))
&& beforePhaseSuccess[i])
{
try
{
phaseListener.afterPhase(event);
}
catch (Throwable t)
{
logger.log(Level.SEVERE, "An Exception occured while processing the " +
"afterPhase method of PhaseListener " + phaseListener +