IntroductionI encountered a situation the other day where I need to include a JSF page based on a parameter passed in via a
<f:viewParam>. This seems like a very reasonable kind of idea. I expected to be able to make the
<ui:include/>use a dynamically set
srcparameter using EL from the
<f:viewParam>. This is where I went wrong (the idea was good...). The
<ui:include/>is a tag handler. It is evaluated on Restore View Phase. The value processing does not take place until the Apply Request Values Phase. This presents a problem since the EL binding for my
<ui:include/>is based on the
<f:viewParam>which is a
UIInputobject. So we are out of phase. The page will display the results, but all the AJAX will not work.
A SolutionA solution to the problem involves using static
<ui:include/>elements wrapped in
<ui:fragment/>elements. This allows the tag handler to resolve the page to include, and then the fragment determines (via late binding) whether to display the page based on the
<f:viewParam>passed. The page is supported by a
@ViewScopedbean to keep the page in scope.