Micha Kops avatar Micha Kops committed 9044c56

Java Server Faces / JSF2 Tutorial Sources added

Comments (0)

Files changed (8)

jsf2-tutorial-part1/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>com.hascode.jsf</groupId>
+	<artifactId>jsf2-tutorial</artifactId>
+	<packaging>war</packaging>
+	<version>0.0.1-SNAPSHOT</version>
+	<name>hasCode.com -Java Server Faces 2 Maven Tutorial</name>
+	<url>http://maven.apache.org</url>
+	<repositories>
+		<repository>
+			<id>maven2-repository.dev.java.net</id>
+			<name>Java.net Repository for Maven</name>
+			<url>http://download.java.net/maven/2</url>
+		</repository>
+	</repositories>
+	<dependencies>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.1</version>
+			<scope>test</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.faces</groupId>
+			<artifactId>jsf-api</artifactId>
+			<version>2.0.2</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>com.sun.faces</groupId>
+			<artifactId>jsf-impl</artifactId>
+			<version>2.0.2</version>
+			<scope>compile</scope>
+		</dependency>
+		<dependency>
+			<groupId>jstl</groupId>
+			<artifactId>jstl</artifactId>
+			<version>1.2</version>
+		</dependency>
+	</dependencies>
+	<build>
+		<finalName>jsf2-tutorial</finalName>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<version>2.0.2</version>
+				<configuration>
+					<source>1.6</source>
+					<target>1.6</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+</project>

jsf2-tutorial-part1/src/main/java/com/hascode/tutorial/jsf2_tutorial/bean/UserBean.java

+package com.hascode.tutorial.jsf2_tutorial.bean;
+
+import java.util.Date;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.ValidatorException;
+
+@ManagedBean
+@SessionScoped
+public class UserBean {
+	protected String nickname;
+	protected String email;
+	protected Date birthday;
+
+	/**
+	 * @return the nickname
+	 */
+	public String getNickname() {
+		return nickname;
+	}
+
+	/**
+	 * @param nickname
+	 *            the nickname to set
+	 */
+	public void setNickname(String nickname) {
+		this.nickname = nickname;
+	}
+
+	/**
+	 * @return the email
+	 */
+	public String getEmail() {
+		return email;
+	}
+
+	/**
+	 * @param email
+	 *            the email to set
+	 */
+	public void setEmail(String email) {
+		this.email = email;
+	}
+
+	/**
+	 * @return the birthday
+	 */
+	public Date getBirthday() {
+		return birthday;
+	}
+
+	/**
+	 * @param birthday
+	 *            the birthday to set
+	 */
+	public void setBirthday(Date birthday) {
+		this.birthday = birthday;
+	}
+
+	/**
+	 * stupid simple email validation
+	 * 
+	 * @param context
+	 * @param validated
+	 * @param value
+	 */
+	public void validateEmail(FacesContext context, UIComponent validated,
+			Object value) {
+		// simple stupid validation
+		String mail = (String) value;
+		if (!mail.matches(".+\\@.+\\..+")) {
+			FacesMessage msg = new FacesMessage("This is not an e-mail!");
+			throw new ValidatorException(msg);
+		}
+	}
+}

jsf2-tutorial-part1/src/main/webapp/WEB-INF/.faces-config.xml.jsfdia

+<?xml version="1.0" encoding="UTF-8"?>
+<PROCESS model-entity="JSFProcess">
+ <PROCESS-ITEM NAME="rules:#registration.xhtml"
+  PATH="/registration.xhtml" SHAPE="32,17,0,0" model-entity="JSFProcessGroup">
+  <PROCESS-ITEM ID="rules:#registration.xhtml:0" NAME="item"
+   PATH="/registration.xhtml" model-entity="JSFProcessItem">
+   <PROCESS-ITEM-OUTPUT ID="success::#registration_success.xhtml"
+    NAME="output" PATH="/registration_success.xhtml"
+    TARGET="rules:#registration_success.xhtml" TITLE="success" model-entity="JSFProcessItemOutput"/>
+  </PROCESS-ITEM>
+ </PROCESS-ITEM>
+ <PROCESS-ITEM NAME="rules:#registration_success.xhtml"
+  PATH="/registration_success.xhtml" SHAPE="240,33,0,0" model-entity="JSFProcessGroup"/>
+</PROCESS>

jsf2-tutorial-part1/src/main/webapp/WEB-INF/faces-config.xml

+<?xml version="1.0" encoding="UTF-8"?>
+<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ 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-facesconfig_2_0.xsd">
+ <name>app</name>
+ <navigation-rule>
+  <from-view-id>/registration.xhtml</from-view-id>
+  <navigation-case>
+   <from-outcome>success</from-outcome>
+   <to-view-id>/registration_success.xhtml</to-view-id>
+  </navigation-case>
+ </navigation-rule>
+</faces-config>

jsf2-tutorial-part1/src/main/webapp/WEB-INF/web.xml

+<!DOCTYPE web-app PUBLIC
+ "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+ "http://java.sun.com/dtd/web-app_2_3.dtd" >
+<web-app>
+    <display-name>hasCode.com - Java Server Faces 2 Tutorial</display-name>
+    <context-param>
+        <param-name>javax.faces.PROJECT_STAGE</param-name>
+        <param-value>Development</param-value>
+    </context-param>
+    <servlet>
+        <servlet-name>Faces Servlet</servlet-name>
+        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+    </servlet>
+    <servlet-mapping>
+        <servlet-name>Faces Servlet</servlet-name>
+        <url-pattern>*.xhtml</url-pattern>
+    </servlet-mapping>
+    <welcome-file-list>
+		<welcome-file>/registration.xhtml</welcome-file>
+	</welcome-file-list>
+</web-app>

jsf2-tutorial-part1/src/main/webapp/decorator.xhtml

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:h="http://java.sun.com/jsf/html"
+      xmlns:f="http://java.sun.com/jsf/core"
+      xmlns:ui="http://java.sun.com/jsf/facelets">
+    <h:head>
+        <title><ui:insert name="title">hasCode.com - Default Title</ui:insert></title>
+    </h:head>
+    <h:body>
+    	<h1><ui:insert name="title">hasCode.com - Default Heading</ui:insert></h1>
+       	<ui:insert name="body">Default Body</ui:insert>
+    </h:body>
+</html>

jsf2-tutorial-part1/src/main/webapp/registration.xhtml

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:h="http://java.sun.com/jsf/html"
+      xmlns:f="http://java.sun.com/jsf/core"
+      xmlns:ui="http://java.sun.com/jsf/facelets">
+	<ui:composition template="/decorator.xhtml">
+		<ui:define name="title">hasCode.com - Java Server Faces Tutorial - Registration</ui:define>
+		<ui:define name="body">
+			<h:form>
+	       		<div id="registration">
+	       			<label>Nickname</label>
+	       			<h:inputText label="Nickname" id="nname" value="#{userBean.nickname}" required="true"/>
+	       			<h:message for="nname"/>
+	       			<br/>
+	       			<label>E-Mail</label>
+	       			<h:inputText label="E-Mail" id="email" value="#{userBean.email}" required="true" validator="#{userBean.validateEmail}"/>
+	       			<h:message for="email"/>
+	       			<br/>
+	       			<label>Birthday</label>
+	       			<h:inputText label="Birthday" id="birthday" value="#{userBean.birthday}" required="true">
+						<f:convertDateTime pattern="yyy-MM-dd"/>
+					</h:inputText> (yyyy-mm-dd)
+					<h:message for="birthday"/><hr/>
+					<h:messages/>
+	       			<br/>
+	       			<h:commandButton action="success" value="Register" />
+	       		</div>
+       		</h:form>
+		</ui:define>
+	</ui:composition>
+</html>

jsf2-tutorial-part1/src/main/webapp/registration_success.xhtml

+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:h="http://java.sun.com/jsf/html"
+      xmlns:f="http://java.sun.com/jsf/core"
+      xmlns:ui="http://java.sun.com/jsf/facelets">
+	<ui:composition template="/decorator.xhtml">
+		<ui:define name="title">hasCode.com - Java Server Faces Tutorial - Registration Successful</ui:define>
+		<ui:define name="body">
+			Registration was successful
+			<br/>
+			Nickname: #{userBean.nickname}
+		</ui:define>
+	</ui:composition>
+</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.