Here we go..
pom.xml
web.xml
faces-config.xml
FooBacking.java
page1.xhtml
page2.xhtml
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>biz.tugay</groupId> <artifactId>jsf-two</artifactId> <packaging>war</packaging> <version>0.1-SNAPSHOT</version> <name>jsf-two Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <!-- JSF related dependencies --> <dependency> <groupId>javax.faces</groupId> <artifactId>javax.faces-api</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>com.sun.faces</groupId> <artifactId>jsf-impl</artifactId> <version>2.2.13</version> </dependency> <!-- // JSF related dependencies --> <!-- Already in Tomcat so scope is provided --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.el</groupId> <artifactId>javax.el-api</artifactId> <version>2.2.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <!--// Already in Tomcat --> </dependencies> <properties> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <build> <finalName>jsf-two</finalName> <plugins> <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.2.1.v20140609</version> <configuration> <scanIntervalSeconds>2</scanIntervalSeconds> <webApp> <contextPath>/</contextPath> </webApp> </configuration> </plugin> </plugins> </build> </project>
web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <context-param> <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name> <param-value>true</param-value> </context-param> <servlet> <servlet-name>facesServlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>facesServlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>page1.xhtml</welcome-file> </welcome-file-list> </web-app>
faces-config.xml
<?xml version="1.0" encoding="UTF-8"?> <faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"> </faces-config>
FooBacking.java
package biz.tugay.jsfone; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; import java.util.Date; /** * 2016/05/17 * koray@tugay.biz */ @ManagedBean @RequestScoped public class FooBacking { private Date paymentDate; public Date getPaymentDate() { return paymentDate; } public void setPaymentDate(Date paymentDate) { this.paymentDate = paymentDate; } }
page1.xhtml
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html"> <f:view> <h:body> <div> <h:form prependId="false" id="foo"> <h:outputLabel for="paymentDate" value="Payment Date:" /> <h:inputText value="#{fooBacking.paymentDate}" id="paymentDate"> <f:convertDateTime pattern="yy/MM/dd" /> </h:inputText> <br /> <h:commandButton id="submitButton" value="Submit Form" action="page2?faces-redirect=true&includeViewParams=true"/> </h:form> </div> </h:body> </f:view> </html>
page2.xhtml
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://xmlns.jcp.org/jsf/core" xmlns:h="http://xmlns.jcp.org/jsf/html"> <f:view> <f:metadata> <f:viewParam name="paymentDate" value="#{fooBacking.paymentDate}"> <f:convertDateTime /> </f:viewParam> </f:metadata> <h:body> <div> Date you provided was a: <h:outputText value="#{fooBacking.paymentDate}"> <f:convertDateTime pattern="E - (dd/MM/yyyy)"/> </h:outputText> </div> </h:body> </f:view> </html>Web page in action: