Enlightensoft's Blog

Helping in your each step

  • Categories

  • Authors

Archive for the ‘JSF’ Category

All about JSF (Java Server Faces)

Which JSF you like???

Posted by Pankil Patel on July 11, 2011

Advertisements

Posted in JSF | Leave a Comment »

How to solve URL problem in JSF???

Posted by Pankil Patel on September 20, 2010

How to solve URL problem in JSF???

One common URL problem in JSF is that: It is displaying last visited page URL instead of current page URL….

Solution of this problem is: Add <redirect /> tag in all <navigation-case> to make URL proper.

Without it, it will display last URL (one page old) instead of current URL:

Ex:

<navigation-case>
<from-outcome>failure</from-outcome>
<to-view-id>/jsps/error.jsp</to-view-id>
<redirect />
</navigation-case>

Posted in JSF | 4 Comments »

How to integrate JSF with Spring

Posted by Pankil Patel on September 17, 2010

Step 1: Add required jars into your project

Here in this example we required:

  • commons-beanutils.jar
  • commons-collections.jar
  • commons-digester.jar
  • commons-el-1.0.jar
  • jboss-faces.jar
  • jsf-api.jar
  • jsf-impl.jar
  • standard.jar

If want to add richfaces support into your application then add below jar also:

  • richfaces-api-3.2.1.GA.jar
  • richfaces-impl-3.2.1.GA.jar
  • richfaces-ui-3.2.1.GA.jar

Step 2: Edit your web.xml for jsf support

  • Add entry of context-param

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
/WEB-INF/faces-config.xml,/WEB-INF/faces-managed-beans.xml,/WEB-INF/faces-navigation.xml
</param-value>
</context-param>

  • Add FacesServlet and it’s servlet-mapping in last for their appropriate section.

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

If you are using Richfaces add also below filter and it’s mapping section into web.xml

<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

Step 3: Add faces-config.xml, faces-managed-beans.xml and faces-navigation.xml files under WEB-INF folder

For Demo and more detail download

http://www.javaworld.com/javaworld/jw-11-2002/jsf/jw-1129-jsf.jar

You can use same faces-managed-beans.xml and faces-navigation.xml in this example as per your customization.

Best of luck………………………..

Posted in JSF | 1 Comment »

JavaEE 6 application with JSF2, EJB3 and JPA – Using Netbeans 6.8

Posted by Pankil Patel on April 12, 2010

http://wiki.netbeans.org/DevelopJavaEE6App

Posted in JSF | 1 Comment »

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

Posted in JSF | Leave a Comment »