How to pass new hidden value to backing bean in JSF

In some cases, you may need to pass a new hidden value to a backing bean. Generally, there are two ways : 1. HTML Tag + getRequestParameterMap() Render hidden field with plain HTML input, hard-coded new hidden value and access in backing bean via getRequestParameterMap() method. JSF… <h:form id="myForm"> <input type="hidden" name="hidden1" value="this is hidden2" …

Read more

JSF 2 hidden value example

In JSF, you can use the <h:inputHidden /> tag to render a HTML hidden value field. For example, JSF tag… <h:inputHidden value="some text" /> Render this HTML code… <input type="hidden" name="random value" value="some text" /> JSF hidden field example A JSF 2 example to render a hidden field via <h:inputHidden /> tag, and access the …

Read more

JSF 2 textarea example

In JSF, you can use the <h:inputTextarea /> tag to render a HTML textarea field. For example, JSF tag… <h:inputTextarea cols="30" rows="10" /> Render this HTML code… <textarea name="random value" cols="30" rows="10"></textarea> JSF textarea example A full JSF 2 example to render a textarea field via <h:inputTextarea /> tag. 1. Managed Bean A managed bean, …

Read more

JSF 2 password example

In JSF, you can use the <h:inputSecret /> tag to render a HTML input of type=”password”, password field. For example, JSF tag… <h:inputSecret /> Render this HTML code… <input type="password" name="j_idt6:j_idt7" /> P.S The name attribute value is randomly generated by JSF. JSF password example A full JSF 2 example to render a password input …

Read more

JSF 2 textbox example

In JSF, you can use the <h:inputText /> tag to render a HTML input of type=”text”, text box. For example, JSF tag… <h:inputText /> Render this HTML code… <input type="text" name="j_idt6:j_idt7" /> P.S The name attribute value is randomly generated by JSF. JSF textbox example A full JSF 2 example to render a textbox input …

Read more

Where is JSF 2 taglib JavaDoc?

Problem Often times, you need to know the detail attribute of a JSF HTML form tag, e.g f:inputText. The JSF 2 tag library JavaDoc is very hard to find, even Google didn’t return any result of it? Solution Actually, JavaServer(TM) Faces, both 1.x or 2.x are available at this JSF official website. Unfortunately, JSF official …

Read more

How to add a global navigation rule in JSF?

Problem A global navigation rule is a rule that applies to all pages. For example, apply a “logout” navigation rule that every pages are allow to access. Is there a way to configure it in JSF? Solution In JSF, wildcard is supported in navigation rule, you can use a “*” to specify a navigation rule …

Read more

JSF : Page Forward vs Page Redirect

By default, JSF will performs a server page forward while navigating to another page. See following example to differentiate between page forward and page redirect. A “start.xhtml” page, with a button navigate to “page1.xhtml” page. 1. Page Forward Here’s how the page forward works : Browser send a “GET” request to URL : http://localhost:8080/JavaServerFaces/faces/start.xhtml. JSF …

Read more

JSF “from-action” navigation rule example

In JSF navigation rule, you may encounter a situation where two separate actions return a same “outcome” in a single page. In this case, you can use “from-action” element to differentiate the two navigation cases. See following example : 1. Managed Bean A managed bean, with two actions which return a same outcome – “success”. …

Read more

Conditional Navigation Rule in JSF 2.0

JSF 2 comes with a very flexible conditional navigation rule to solve the complex page navigation flow, see the following conditional navigation rule example : 1. JSF Page A simple JSF page, with a button to move from this page to the payment page. start.xhtml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" …

Read more

Implicit Navigation in JSF 2.0

In JSF 1.2, all the page navigation are required to declare in the “faces-config.xml” file like this : … <navigation-rule> <from-view-id>page1.xhtml</from-view-id> <navigation-case> <from-outcome>page2</from-outcome> <to-view-id>/page2.xhtml</to-view-id> </navigation-case> </navigation-rule> … In JSF 2, it treats “outcome” as the page name, for example, navigate to “page1.xhtml”, you have to put the “outcome” as “page1”. This mechanism is called “Implicit …

Read more

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