Injecting Managed beans in JSF 2.0

In JSF 2.0, a new @ManagedProperty annotation is used to dependency injection (DI) a managed bean into the property of another managed bean. Let see a @ManagedProperty example : MessageBean.java – A managed bean named “message“. import java.io.Serializable; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; @ManagedBean(name="message") @SessionScoped public class MessageBean implements Serializable { //business logic and whatever methods… …

Read more

JSF 2.0 : managed bean x does not exist, Check that appropriate getter and/or setter methods exist

Problem In JSF 2.0, while using the @ManagedProperty annotation to DI the bean into the field of another bean, HelloBean.java @ManagedBean @SessionScoped public class HelloBean implements Serializable { @ManagedProperty(value="#{message}") private MessageBean messageBean; MessageBean.java @ManagedBean(name="message") @SessionScoped public class MessageBean implements Serializable { It hits the following error message. An Error Occurred: Unable to create managed bean …

Read more

How to split faces-config.xml into multiple files?

Problem In JSF, the faces-config.xml file can used to includes manages beans, navigation rules or any JSF faces configurations. But, putting all the configurations into a single faces-config.xml file will cause this file become huge very fast, and causing a serious maintainability issue. Solution Actually, you can split the faces-config.xml into multiple smaller files, each …

Read more

Configure Managed Beans in JSF 2.0

In JSF 2.0, Java bean that can be accessed from JSF page is called Managed Bean. The managed bean can be a normal Java bean, which contains the getter and setter methods, business logic or even a backing bean (a bean contains all the HTML form value). There are two ways to configure the managed …

Read more

JSF 2.0 and Resource Bundles example

In this tutorial, we demonstrate the use of resource bundle to display messages in JSF 2.0. For maintainability concern, it’s always recommended to put all the messages in properties file, instead of hard-code the message in page directly. 1. Properties File Create a properties file, contains message for the page, and put it into the …

Read more

JSF 2.0 : <f:ajax> contains an unknown id

Problem A JSF’s button with Ajax support… <h:outputText id="output" value="#{helloBean.sayWelcome}" /> <h:form> <h:inputText id="name" value="#{helloBean.name}"></h:inputText> <h:commandButton value="Welcome Me"> <f:ajax execute="name" render="output" /> </h:commandButton> </h:form> When this page is displayed, it prompts the following error message javax.faces.FacesException: <f:ajax> contains an unknown id ‘output’ – cannot locate it in the context of the component j_idt8 Obviously, the …

Read more

JSF 2.0 + Ajax hello world example

In JSF 2.0, coding Ajax is just like coding a normal HTML tag, it’s extremely easy. In this tutorial, you will restructure the last JSF 2.0 hello world example, so that, when the button is clicked, it will make an Ajax request instead of submitting the whole form. 1. JSF 2.0 Page A JSF 2.0 …

Read more

How to make Eclipse IDE supports JSF 2.0

In Eclipse Ganymede (v3.4) or Galileo (v3.5), it supports until JSF 1.2 only. For JSF 2.0, upgrade your Eclipse to version Helios (v3.6) onward, it has full support of Java EE 6 support, including JSF 2.0. Here’s a quick guide to show you how to enable JSF 2.0 features like code assist and visual JSF …

Read more

JSF 2.0 hello world example

In this tutorial, we will show you how to develop a JavaServer Faces (JSF) 2.0 hello world example, shows list of JSF 2.0 dependencies, basic annotations and configurations. Project Environment This JSF 2.0 example is built with following tools and technologies JSF 2.1.7 Maven 3 Eclipse 3.6 JDK 1.6 Tomcat 6.0.26 First, review the final …

Read more

JSF 2.0 + Tomcat : It appears the JSP version of the container is older than 2.1…

Problem While deploying JSF 2.0 web application to Tomcat 6.0.26, hits the “JSP version of the container is older than 2.1” exception and failed to start the Tomcat server. But the JSP api v2.1 is included in the project class path, why the Tomcat is still saying that JSP version is older than 2.1? <dependency> …

Read more

java.lang.ClassNotFoundException : javax.servlet.jsp.jstl.core.Config

Problem While deploying JSF 2.0 web application to Tomcat 6.0.26, hits following jstl class not found error. java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config … Caused by: java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config … 18 more Solution By default, Tomcat container doesn’t contain any jstl library. To fix it, declares jstl.jar in your Maven pom.xml file. <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> Note Please refer …

Read more

java.lang.IllegalArgumentException: javax.faces.context.ExceptionHandlerFactory

Problem In Eclipse IDE, while deploying a JSF 2.0 web application to Tomcat 6.0.26, hits the following exception and failed to start the Tomcat server. P.S Both jsf-api-2.1.0-b03.jar and jsf-impl-2.1.0-b03.jar libraries are included in the project classpath. INFO: Unsanitized stacktrace from failed start… java.lang.IllegalArgumentException: javax.faces.context.ExceptionHandlerFactory at javax.faces.FactoryFinder.validateFactoryName(FactoryFinder.java:630) at javax.faces.FactoryFinder.setFactory(FactoryFinder.java:287) … SEVERE: Critical error during deployment: …

Read more