1

I'm using PrimeFaces and I have next jsf page:

<h:form id="form1111">

            <p:commandLink value="Include Page" actionListener="#{dynaInclBean.includePage}" update="dynInclTabView"/>
            <p:tabView id="dynInclTabView" dynamic="true">
                <p:tab title="Somename" binding="#{dynaInclBean.tab}"/>
            </p:tabView>
    </h:form>

My backing bean:

private Tab tab;

public Tab getTab() {
    return tab;
}

public void setTab(Tab tab) {
    this.tab = tab;
}

public void includePage() throws IOException
{
    FaceletContext faceletContext = (FaceletContext) FacesContext.getCurrentInstance().getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
    faceletContext.includeFacelet(tab, "playerPhoto.xhtml");
}

I want to include page to the tab. When I calling inlcudePage() I get an exception: org.apache.myfaces.view.facelets.el.ContextAwareELException: javax.el.ELException: java.lang.NullPointerException

What am I doing wrong?

xeal
  • 31
  • 3

1 Answers1

0

This construct is indeed not supported in MyFaces. Therein, the FaceletContext is only available during view build time (the restore view phase) and is released immediately by end of this phase. It would throw a NPE like that in all other phases because the internal Facelet context is been released and nulled out.

This construct works in Mojarra though.

Your best try is to use <ui:include src="#{bean.include}"> or multiple conditionally rendered includes. There is still no "holy grail" solution for this problem. The problem is clearly understood, but the solution is hard given the JSF/Facelets lifecycle.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I need to make a tabView with the ability to add and remove tabs, so I need to include page to the tab on the java side – xeal Dec 18 '12 at 12:37
  • Just provide a dynamic list of tabs to ``. See also http://stackoverflow.com/questions/11961692/how-to-add-button-for-adding-new-tabs-near-last-tab/11962703#11962703 – BalusC Dec 18 '12 at 12:48