Commits

Micha Kops committed 32204a6

JSF2 / PrimeFaces Tutorial added

  • Participants
  • Parent commits 9044c56

Comments (0)

Files changed (13)

jsf2-primefaces/.classpath

+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" output="target/classes" path="src/main/java"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+	<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+	<classpathentry kind="output" path="target/classes"/>
+</classpath>

jsf2-primefaces/.project

+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>jsf2-tutorial</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.maven.ide.eclipse.maven2Builder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.maven.ide.eclipse.maven2Nature</nature>
+	</natures>
+</projectDescription>

jsf2-primefaces/.settings/org.eclipse.jdt.core.prefs

+#Sat Nov 13 17:08:50 CET 2010
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6

jsf2-primefaces/.settings/org.maven.ide.eclipse.prefs

+#Sat Nov 13 17:08:50 CET 2010
+activeProfiles=
+eclipse.preferences.version=1
+fullBuildGoals=process-test-resources
+includeModules=false
+resolveWorkspaceProjects=true
+resourceFilterGoals=process-resources resources\:testResources
+skipCompilerPlugin=true
+version=1

jsf2-primefaces/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-primefaces-tutorial</artifactId>
+	<packaging>war</packaging>
+	<version>0.0.1-SNAPSHOT</version>
+	<name>hasCode.com -Java Server Faces 2 with PrimeFaces 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>
+		<repository>
+			<id>JBoss repository</id>
+			<url>http://repository.jboss.com/maven2/</url>
+		</repository>
+		<repository>
+			<id>prime-repo</id>
+			<name>Prime Technology Maven Repository</name>
+			<url>http://repository.prime.com.tr</url>
+			<layout>default</layout>
+		</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>
+		<dependency>
+			<groupId>org.primefaces</groupId>
+			<artifactId>primefaces</artifactId>
+			<version>2.2.RC1</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-primefaces/src/main/java/com/hascode/tutorial/jsf2_tutorial/bean/UserBean.java

+package com.hascode.tutorial.jsf2_tutorial.bean;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+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);
+		}
+	}
+
+	public List<String> suggestEmail(String entered) {
+		List<String> list = new ArrayList<String>();
+		for (int i = 1; i < 11; i++) {
+			list.add(entered + i + "@hascode.com");
+		}
+		return list;
+	}
+}

jsf2-primefaces/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-primefaces/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-primefaces/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 and PrimeFaces Tutorial</display-name>
+	<context-param>
+		<param-name>javax.faces.PROJECT_STAGE</param-name>
+		<param-value>Development</param-value>
+	</context-param>
+	<context-param>
+		<param-name>com.sun.faces.allowTextChildren</param-name>
+		<param-value>true</param-value>
+	</context-param>
+	<servlet>
+		<servlet-name>Faces Servlet</servlet-name>
+		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+	</servlet>
+	<servlet>
+		<servlet-name>Resource Servlet</servlet-name>
+		<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
+	</servlet>
+	<servlet-mapping>
+		<servlet-name>Faces Servlet</servlet-name>
+		<url-pattern>*.xhtml</url-pattern>
+	</servlet-mapping>
+	<servlet-mapping>
+		<servlet-name>Resource Servlet</servlet-name>
+		<url-pattern>/primefaces_resource/*</url-pattern>
+	</servlet-mapping>
+	<welcome-file-list>
+		<welcome-file>/registration.xhtml</welcome-file>
+	</welcome-file-list>
+</web-app>

jsf2-primefaces/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-primefaces/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"
+	xmlns:p="http://primefaces.prime.com.tr/ui">
+<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"><p:accordionPanel autoHeight="false">
+				<p:tab title="Nickname">
+					<h:panelGrid columns="2" cellpadding="10">
+						<label>Nickname</label>
+						<h:inputText label="Nickname" id="nname"
+							value="#{userBean.nickname}" required="true" />
+						<h:message for="nname" />
+					</h:panelGrid>
+				</p:tab>
+				<p:tab title="E-Mail">
+					<h:panelGrid columns="2" cellpadding="10">
+						<label>E-Mail</label>
+						<p:autoComplete id="acSimple" value="#{userBean.email}"
+							required="true" validator="#{userBean.validateEmail}"
+							completeMethod="#{userBean.suggestEmail}" />
+						<h:message for="email" />
+					</h:panelGrid>
+				</p:tab>
+				<p:tab title="Birthday">
+					<h:panelGrid columns="2" cellpadding="10">
+						<label>Birthday</label>
+						<p:calendar value="#{userBean.birthday}" required="true" />
+						<h:message for="birthday" />
+					</h:panelGrid>
+				</p:tab>
+			</p:accordionPanel> <h:commandButton action="success" value="Register" /></div>
+			<h:messages />
+		</h:form>
+	</ui:define>
+</ui:composition>
+</html>

jsf2-primefaces/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>

jsf2-tutorial-part1/pom.xml

 			<name>Java.net Repository for Maven</name>
 			<url>http://download.java.net/maven/2</url>
 		</repository>
+		<repository>
+			<id>JBoss repository</id>
+			<url>http://repository.jboss.com/maven2/</url>
+		</repository>
 	</repositories>
 	<dependencies>
 		<dependency>