I have a JSF 2.0 project that I am unable to obtain a FaceletContext from.
Here is the setup from my web.xml:
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PARTIAL_STATE_SAVING</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FULL_STATE_SAVING_VIEW_IDS</param-name>
<param-value>/index.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
I can obtain the FacesContext, but not the FaceletContext. The following lines of code are where the issue lies:
FacesContext fctx = FacesContext.getCurrentInstance(); //works
//FaceletContext f2ctx = (FaceletContext) fctx.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
FaceletContext f2ctx = (FaceletContext) fctx.getELContext().getContext(FaceletContext.class);
Can anyone assist?
Update:
The above was a snippet from my overall goal: loading a facelet file containing a dialog on demand, then add it to a parent to display. The code below is incomplete, but should explain what I'm getting at. Note that the app uses the Primefaces library, hence the RequestContext object.
public void launch() {
form.getChildren().clear();
FacesContext fctx = FacesContext.getCurrentInstance();
for (Object o: fctx.getAttributes().keySet()) {
System.out.println(o.toString());
}
FaceletContext f2ctx = (FaceletContext) fctx.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
//FaceletContext f2ctx = (FaceletContext) fctx.getELContext().getContext(FaceletContext.class);
dialog = new Dialog();
try {
f2ctx.includeFacelet(dialog, "/WEB-INF/facelets/dialog/manager.xhtml");
form.getChildren().add(dialog);
} catch (IOException ex) {
log.debug(ex.toString());
}
RequestContext.getCurrentInstance().update("mainPageCenterForm");
}