* @see javax.faces.view.facelets.FaceletHandler#apply(javax.faces.view.facelets.FaceletContext, javax.faces.component.UIComponent)
*/
public void apply(FaceletContext ctx, UIComponent parent) throws IOException, FacesException, FaceletException,
ELException
{
AbstractFaceletContext actx = (AbstractFaceletContext) ctx;
FaceletCompositionContext fcc = FaceletCompositionContext.getCurrentInstance(ctx);
String path;
boolean markInitialState = false;
if (!src.isLiteral())
{
String uniqueId = fcc.startComponentUniqueIdSection();
//path = getSrcValue(actx, fcc, parent, uniqueId);
String restoredPath = (String) ComponentSupport.restoreInitialTagState(ctx, fcc, parent, uniqueId);
if (restoredPath != null)
{
// If is not restore view phase, the path value should be
// evaluated and if is not equals, trigger markInitialState stuff.
if (!PhaseId.RESTORE_VIEW.equals(ctx.getFacesContext().getCurrentPhaseId()))
{
path = this.src.getValue(ctx);
if (path == null || path.length() == 0)
{
return;
}
if (!path.equals(restoredPath))
{
markInitialState = true;
}
}
else
{
path = restoredPath;
}
}
else
{
//No state restored, calculate path
path = this.src.getValue(ctx);
}
ComponentSupport.saveInitialTagState(ctx, fcc, parent, uniqueId, path);
}
else
{
path = this.src.getValue(ctx);
}
try
{
if (path == null || path.length() == 0)
{
return;
}
VariableMapper orig = ctx.getVariableMapper();
ctx.setVariableMapper(new VariableMapperWrapper(orig));
try
{
//Only ui:param could be inside ui:include.
//this.nextHandler.apply(ctx, null);
URL url = null;
boolean oldMarkInitialState = false;
Boolean isBuildingInitialState = null;
// if we are in ProjectStage Development and the path equals "javax.faces.error.xhtml"
// we should include the default error page
if (ctx.getFacesContext().isProjectStage(ProjectStage.Development)
&& ERROR_PAGE_INCLUDE_PATH.equals(path))
{
url =ClassUtils.getResource(ERROR_FACELET);
}
if (markInitialState)
{
//set markInitialState flag
oldMarkInitialState = fcc.isMarkInitialState();
fcc.setMarkInitialState(true);
isBuildingInitialState = (Boolean) ctx.getFacesContext().getAttributes().put(
"javax.faces.IS_BUILDING_INITIAL_STATE", Boolean.TRUE);
}
try
{
if (_params != null)
{
// ui:include defines a new TemplateContext, but ui:param EL expressions
// defined inside should be built before the new context is setup, to
// apply then after. The final effect is EL expressions will be resolved
// correctly when nested ui:params with the same name or based on other
// ui:params are used.
String[] names = new String[_params.length];
ValueExpression[] values = new ValueExpression[_params.length];
for (int i = 0; i < _params.length; i++)
{
names[i] = _params[i].getName(ctx);
values[i] = _params[i].getValue(ctx);
}
actx.pushTemplateContext(new TemplateContextImpl());
for (int i = 0; i < _params.length; i++)
{
_params[i].apply(ctx, parent, names[i], values[i]);
}
}
else
{
actx.pushTemplateContext(new TemplateContextImpl());
}
if (url == null)
{
ctx.includeFacelet(parent, path);
}
else
{
ctx.includeFacelet(parent, url);
}
}
finally
{
if (markInitialState)
{
//unset markInitialState flag
if (isBuildingInitialState == null)
{
ctx.getFacesContext().getAttributes().remove(
"javax.faces.IS_BUILDING_INITIAL_STATE");
}
else
{
ctx.getFacesContext().getAttributes().put(
"javax.faces.IS_BUILDING_INITIAL_STATE", isBuildingInitialState);
}
fcc.setMarkInitialState(oldMarkInitialState);
}
actx.popTemplateContext();
}
}
finally
{
ctx.setVariableMapper(orig);