Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

JSF

Posted by Pankil Patel on February 18, 2010

1) How to get FacesContext from HTTP ServletContext

public static FacesContext getFacesContext(HttpServletRequest request, HttpServletResponse response) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext == null) {
// Create new Lifecycle.
LifecycleFactory lifecycleFactory = (LifecycleFactory) FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
Lifecycle lifecycle = lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);

// Create new FacesContext.
FacesContextFactory contextFactory = (FacesContextFactory) FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
facesContext = contextFactory.getFacesContext(request.getSession()
.getServletContext(), request, response, lifecycle);

// Create new View.
UIViewRoot view = facesContext.getApplication().getViewHandler().createView(facesContext, “”);
facesContext.setViewRoot(view);

// Set current FacesContext.
FacesContextWrapper.setCurrentInstance(facesContext);
}

return facesContext;
}

private static abstract class FacesContextWrapper extends FacesContext {
protected static void setCurrentInstance(FacesContext facesContext) {
FacesContext.setCurrentInstance(facesContext);
}
}

2) Don’t Use primefaces-2.0 with JSF 1.2 instead of it use primefaces-1.0

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: