Today i will write something about switching from FacesContext to ServletContext (JSF to Servlet ), To getting The facesContext in Servlet Class or Controller.
Use This Method .
1. public ExternalDemandController() {
super();
}
2 . public void init(ServletConfig config) throws ServletException {
super.init(config);
}
3. protected FacesContext getFacesContext(HttpServletRequest request, HttpServletResponse response) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null) {
FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
facesContext = contextFactory.getFacesContext(request.getSession().getServletContext(), request, response, lifecycle);
}
return facesContext;
}
Use This Method .
1. public ExternalDemandController() {
super();
}
2 . public void init(ServletConfig config) throws ServletException {
super.init(config);
}
3. protected FacesContext getFacesContext(HttpServletRequest request, HttpServletResponse response) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null) {
FacesContextFactory contextFactory = (FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
LifecycleFactory lifecycleFactory = (LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
facesContext = contextFactory.getFacesContext(request.getSession().getServletContext(), request, response, lifecycle);
}
return facesContext;
}
No comments:
Post a Comment