that's it for today
This commit is contained in:
parent
a33c99cbd2
commit
1c4ffa9a2a
7
.gitignore
vendored
7
.gitignore
vendored
@ -31,3 +31,10 @@
|
|||||||
/Assignments/JavaScript/JavaFXApplication1/nbproject/private/
|
/Assignments/JavaScript/JavaFXApplication1/nbproject/private/
|
||||||
/Assignments/JavaScript/JavaFXApplication1/build/
|
/Assignments/JavaScript/JavaFXApplication1/build/
|
||||||
/Semester 2/Assignments/lab1-CalebFontenot/target/
|
/Semester 2/Assignments/lab1-CalebFontenot/target/
|
||||||
|
/Semester 2/lab2_CalebFontenot/target/
|
||||||
|
/Semester 2/lab3_CalebFontenot/nbproject/private/
|
||||||
|
/Semester 2/lab3_CalebFontenot/build/
|
||||||
|
/Semester 2/ExampleSourceCode/nbproject/private/
|
||||||
|
/Semester 2/QuizBusLogic/target/
|
||||||
|
/Semester 2/lab04_nav1_CalebFontenot/target/
|
||||||
|
/Semester 2/RecursionDemo/target/
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,13 @@
|
|||||||
|
appserver.dir=${env.GLASSFISH_HOME}
|
||||||
|
glassfish=true
|
||||||
|
jsf.api.jar=${appserver.dir}/modules/jsf-api.jar
|
||||||
|
servlet.api.jar=${appserver.dir}/modules/javax.servlet.jar
|
||||||
|
el.api.jar=${appserver.dir}/modules/javax.servlet.jsp.jar
|
||||||
|
jpa.api.jar=${appserver.dir}/modules/javax.persistence.jar
|
||||||
|
jta.api.jar=${appserver.dir}/modules/javax.transaction.jar
|
||||||
|
ejb.api.jar=${appserver.dir}/modules/javax.ejb.jar
|
||||||
|
bean-validation.api.jar=${appserver.dir}/modules/bean-validator.jar
|
||||||
|
cdi.api.jar=${appserver.dir}/modules/weld-osgi-bundle.jar
|
||||||
|
mail.api.jar=${appserver.dir}/modules/mail.jar
|
||||||
|
deploy.dir=${appserver.dir}/domains/domain1/autodeploy
|
||||||
|
|
@ -0,0 +1,113 @@
|
|||||||
|
<project default="install">
|
||||||
|
<property environment="env"/>
|
||||||
|
<property file="build.properties"/>
|
||||||
|
<property file="${app}/tomcat.properties"/>
|
||||||
|
<property name="appdir" value="${basedir}/${app}"/>
|
||||||
|
<basename property="appname" file="${appdir}"/>
|
||||||
|
<property name="builddir" value="${appdir}/build"/>
|
||||||
|
<property name="warfile" value="${builddir}/${appname}.war"/>
|
||||||
|
|
||||||
|
<path id="classpath">
|
||||||
|
<pathelement location="${jsf.api.jar}"/>
|
||||||
|
<pathelement location="${servlet.api.jar}"/>
|
||||||
|
<pathelement location="${el.api.jar}"/>
|
||||||
|
<pathelement location="${cdi.api.jar}"/>
|
||||||
|
<pathelement location="${bean-validation.api.jar}"/>
|
||||||
|
<pathelement location="${jpa.api.jar}"/>
|
||||||
|
<pathelement location="${jta.api.jar}"/>
|
||||||
|
<pathelement location="${ejb.api.jar}"/>
|
||||||
|
<pathelement location="${mail.api.jar}"/>
|
||||||
|
<fileset dir="${appdir}">
|
||||||
|
<include name="lib/*.jar"/>
|
||||||
|
</fileset>
|
||||||
|
</path>
|
||||||
|
|
||||||
|
<target name="init">
|
||||||
|
<fail unless="app" message="Run ant -Dapp=..."/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="prepare" depends="init"
|
||||||
|
description="Create build directory.">
|
||||||
|
<delete dir="${builddir}"/>
|
||||||
|
<mkdir dir="${builddir}"/>
|
||||||
|
<mkdir dir="${builddir}/WEB-INF"/>
|
||||||
|
<mkdir dir="${builddir}/WEB-INF/classes"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="copy" depends="prepare"
|
||||||
|
description="Copy files to build directory.">
|
||||||
|
<copy todir="${builddir}" failonerror="false" verbose="true">
|
||||||
|
<fileset dir="${appdir}/web"/>
|
||||||
|
</copy>
|
||||||
|
<copy todir="${builddir}/WEB-INF/classes"
|
||||||
|
failonerror="false" verbose="true">
|
||||||
|
<fileset dir="${appdir}/src/java">
|
||||||
|
<exclude name="**/*.java"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
<copy todir="${builddir}/WEB-INF" failonerror="false" verbose="true">
|
||||||
|
<fileset dir="${appdir}">
|
||||||
|
<include name="lib/**"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="compile" depends="copy"
|
||||||
|
description="Compile source files.">
|
||||||
|
<javac
|
||||||
|
srcdir="${appdir}/src/java"
|
||||||
|
destdir="${builddir}/WEB-INF/classes"
|
||||||
|
debug="true"
|
||||||
|
deprecation="true">
|
||||||
|
<compilerarg value="-Xlint:unchecked"/>
|
||||||
|
<include name="**/*.java"/>
|
||||||
|
<classpath refid="classpath"/>
|
||||||
|
</javac>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="jsf-libs" if="use-jsf-libs" unless="glassfish">
|
||||||
|
<mkdir dir="${builddir}/WEB-INF/lib"/>
|
||||||
|
<copy file="${jsf.api.jar}" todir="${builddir}/WEB-INF/lib" verbose="true"/>
|
||||||
|
<copy file="${jsf.impl.jar}" todir="${builddir}/WEB-INF/lib" verbose="true"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="el-libs" if="use-el-libs" unless="glassfish">
|
||||||
|
<copy file="${el.api.jar}" todir="${builddir}/WEB-INF/lib"
|
||||||
|
verbose="true" failonerror="false"/>
|
||||||
|
<copy file="${el.impl.jar}" todir="${builddir}/WEB-INF/lib"
|
||||||
|
verbose="true" failonerror="false"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="bean-validation-libs" if="use-bean-validation-libs" unless="glassfish">
|
||||||
|
<copy file="${bean-validation.impl.jar}" todir="${builddir}/WEB-INF/lib"
|
||||||
|
verbose="true" failonerror="false"/>
|
||||||
|
<copy todir="${builddir}/WEB-INF/lib" verbose="true" failonerror="false">
|
||||||
|
<fileset dir="${bean-validation.lib.dir}">
|
||||||
|
<include name="*.jar"/>
|
||||||
|
</fileset>
|
||||||
|
</copy>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="cdi-libs" if="use-cdi-libs" unless="glassfish">
|
||||||
|
<copy file="${cdi.impl.jar}" todir="${builddir}/WEB-INF/lib"
|
||||||
|
verbose="true" failonerror="false"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="tomcat-libs" depends="jsf-libs, el-libs, bean-validation-libs, cdi-libs"/>
|
||||||
|
|
||||||
|
<target name="war" depends="clean, compile, tomcat-libs"
|
||||||
|
description="Build WAR file.">
|
||||||
|
<delete file="${warfile}"/>
|
||||||
|
<jar jarfile="${warfile}" basedir="${builddir}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="install" depends="war"
|
||||||
|
description="Deploy web application.">
|
||||||
|
<copy file="${warfile}" todir="${deploy.dir}"/>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
<target name="clean" depends="init"
|
||||||
|
description="Clean everything.">
|
||||||
|
<delete dir="${builddir}"/>
|
||||||
|
</target>
|
||||||
|
</project>
|
Binary file not shown.
@ -0,0 +1,26 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
// or import javax.faces.bean.ManagedBean;
|
||||||
|
import javax.enterprise.context.SessionScoped;
|
||||||
|
// or import javax.faces.bean.SessionScoped;
|
||||||
|
|
||||||
|
@Named("user") // or @ManagedBean(name="user")
|
||||||
|
@SessionScoped
|
||||||
|
public class UserBean implements Serializable {
|
||||||
|
private String name = "";
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public String getName() { return name; }
|
||||||
|
public void setName(String newValue) { name = newValue; }
|
||||||
|
|
||||||
|
public String getPassword() { return password; }
|
||||||
|
public void setPassword(String newValue) { password = newValue; }
|
||||||
|
|
||||||
|
public String getGreeting() {
|
||||||
|
if (name.length() == 0) return "";
|
||||||
|
else return "Welcome to JSF2 + Ajax, " + name + "!";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5">
|
||||||
|
<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>/faces/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>faces/index.xhtml</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
<context-param>
|
||||||
|
<param-name>javax.faces.PROJECT_STAGE</param-name>
|
||||||
|
<param-value>Development</param-value>
|
||||||
|
</context-param>
|
||||||
|
</web-app>
|
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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">
|
||||||
|
<h:head>
|
||||||
|
<title>Welcome</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form prependId="false">
|
||||||
|
<h3>Please enter your name and password.</h3>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>Name:</td>
|
||||||
|
<td><h:inputText value="#{user.name}" id="name"/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Password:</td>
|
||||||
|
<td><h:inputSecret value="#{user.password}" id="password"/></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<p><h:commandButton value="Login">
|
||||||
|
<f:ajax execute="name password" render="out"/>
|
||||||
|
</h:commandButton></p>
|
||||||
|
<h3><h:outputText id="out" value="#{user.greeting}"/></h3>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,20 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import javax.inject.Named;
|
||||||
|
// or import javax.faces.bean.ManagedBean;
|
||||||
|
import javax.enterprise.context.SessionScoped;
|
||||||
|
// or import javax.faces.bean.SessionScoped;
|
||||||
|
|
||||||
|
@Named("user") // or @ManagedBean(name="user")
|
||||||
|
@SessionScoped
|
||||||
|
public class UserBean implements Serializable {
|
||||||
|
private String name;
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public String getName() { return name; }
|
||||||
|
public void setName(String newValue) { name = newValue; }
|
||||||
|
|
||||||
|
public String getPassword() { return password; }
|
||||||
|
public void setPassword(String newValue) { password = newValue; }
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5">
|
||||||
|
<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>/faces/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>faces/index.xhtml</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
<context-param>
|
||||||
|
<param-name>javax.faces.PROJECT_STAGE</param-name>
|
||||||
|
<param-value>Development</param-value>
|
||||||
|
</context-param>
|
||||||
|
</web-app>
|
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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">
|
||||||
|
<h:head>
|
||||||
|
<title>Welcome</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<h3>Please enter your name and password.</h3>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>Name:</td>
|
||||||
|
<td><h:inputText value="#{user.name}"/></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Password:</td>
|
||||||
|
<td><h:inputSecret value="#{user.password}"/></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<p><h:commandButton value="Login" action="welcome"/></p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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">
|
||||||
|
<h:head>
|
||||||
|
<title>Welcome</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h3>Welcome to JavaServer Faces, #{user.name}!</h3>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,24 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ProblemBean implements Serializable {
|
||||||
|
private ArrayList<Integer> sequence;
|
||||||
|
private int solution;
|
||||||
|
|
||||||
|
public ProblemBean() {}
|
||||||
|
|
||||||
|
public ProblemBean(int[] values, int solution) {
|
||||||
|
sequence = new ArrayList<Integer>();
|
||||||
|
for (int i = 0; i < values.length; i++)
|
||||||
|
sequence.add(values[i]);
|
||||||
|
this.solution = solution;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Integer> getSequence() { return sequence; }
|
||||||
|
public void setSequence(ArrayList<Integer> newValue) { sequence = newValue; }
|
||||||
|
|
||||||
|
public int getSolution() { return solution; }
|
||||||
|
public void setSolution(int newValue) { solution = newValue; }
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
// or import javax.faces.bean.ManagedBean;
|
||||||
|
import javax.enterprise.context.SessionScoped;
|
||||||
|
// or import javax.faces.bean.SessionScoped;
|
||||||
|
|
||||||
|
@Named // or @ManagedBean
|
||||||
|
@SessionScoped
|
||||||
|
public class QuizBean implements Serializable {
|
||||||
|
private ArrayList<ProblemBean> problems = new ArrayList<ProblemBean>();
|
||||||
|
private int currentIndex;
|
||||||
|
private int score;
|
||||||
|
|
||||||
|
public QuizBean() {
|
||||||
|
problems.add(
|
||||||
|
new ProblemBean(new int[] { 3, 1, 4, 1, 5 }, 9)); // pi
|
||||||
|
problems.add(
|
||||||
|
new ProblemBean(new int[] { 1, 1, 2, 3, 5 }, 8)); // fibonacci
|
||||||
|
problems.add(
|
||||||
|
new ProblemBean(new int[] { 1, 4, 9, 16, 25 }, 36)); // squares
|
||||||
|
problems.add(
|
||||||
|
new ProblemBean(new int[] { 2, 3, 5, 7, 11 }, 13)); // primes
|
||||||
|
problems.add(
|
||||||
|
new ProblemBean(new int[] { 1, 2, 4, 8, 16 }, 32)); // powers of 2
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProblems(ArrayList<ProblemBean> newValue) {
|
||||||
|
problems = newValue;
|
||||||
|
currentIndex = 0;
|
||||||
|
score = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getScore() { return score; }
|
||||||
|
|
||||||
|
public ProblemBean getCurrent() { return problems.get(currentIndex); }
|
||||||
|
|
||||||
|
public String getAnswer() { return ""; }
|
||||||
|
public void setAnswer(String newValue) {
|
||||||
|
try {
|
||||||
|
int answer = Integer.parseInt(newValue.trim());
|
||||||
|
if (getCurrent().getSolution() == answer) score++;
|
||||||
|
currentIndex = (currentIndex + 1) % problems.size();
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
title=NumberQuiz
|
||||||
|
heading=Have fun with NumberQuiz!
|
||||||
|
currentScore=Your current score is {0}.
|
||||||
|
guessNext=Guess the next number in the sequence!
|
||||||
|
answer=Your answer:
|
||||||
|
next=Next
|
@ -0,0 +1,6 @@
|
|||||||
|
title=Zahlenquiz
|
||||||
|
heading=Viel Spa\u00df mit dem Zahlenquiz!
|
||||||
|
currentScore=Sie haben {0,choice,0#0 Punkte|1#einen Punkt|2#{0} Punkte}.
|
||||||
|
guessNext=Raten Sie die n\u00e4chste Zahl in der Folge!
|
||||||
|
answer=Ihre Antwort:
|
||||||
|
next=Weiter
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<faces-config 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-facesconfig_2_0.xsd"
|
||||||
|
version="2.0">
|
||||||
|
<application>
|
||||||
|
<locale-config>
|
||||||
|
<default-locale>en</default-locale>
|
||||||
|
<supported-locale>de</supported-locale>
|
||||||
|
</locale-config>
|
||||||
|
<resource-bundle>
|
||||||
|
<base-name>com.corejsf.messages</base-name>
|
||||||
|
<var>msgs</var>
|
||||||
|
</resource-bundle>
|
||||||
|
</application>
|
||||||
|
</faces-config>
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5">
|
||||||
|
<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>/faces/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>faces/index.xhtml</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
<context-param>
|
||||||
|
<param-name>javax.faces.PROJECT_STAGE</param-name>
|
||||||
|
<param-value>Development</param-value>
|
||||||
|
</context-param>
|
||||||
|
</web-app>
|
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<h3>#{msgs.heading}</h3>
|
||||||
|
<p>
|
||||||
|
<h:outputFormat value="#{msgs.currentScore}">
|
||||||
|
<f:param value="#{quizBean.score}"/>
|
||||||
|
</h:outputFormat>
|
||||||
|
</p>
|
||||||
|
<p>#{msgs.guessNext}</p>
|
||||||
|
<p>#{quizBean.current.sequence}</p>
|
||||||
|
<p>
|
||||||
|
#{msgs.answer}
|
||||||
|
<h:inputText value="#{quizBean.answer}"/>
|
||||||
|
</p>
|
||||||
|
<p><h:commandButton value="#{msgs.next}"/></p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,22 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Problem implements Serializable {
|
||||||
|
private String question;
|
||||||
|
private String answer;
|
||||||
|
|
||||||
|
public Problem(String question, String answer) {
|
||||||
|
this.question = question;
|
||||||
|
this.answer = answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQuestion() { return question; }
|
||||||
|
|
||||||
|
public String getAnswer() { return answer; }
|
||||||
|
|
||||||
|
// override for more sophisticated checking
|
||||||
|
public boolean isCorrect(String response) {
|
||||||
|
return response.trim().equalsIgnoreCase(answer);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,103 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import javax.inject.Named;
|
||||||
|
// or import javax.faces.bean.ManagedBean;
|
||||||
|
import javax.enterprise.context.SessionScoped;
|
||||||
|
// or import javax.faces.bean.SessionScoped;
|
||||||
|
|
||||||
|
@Named // or @ManagedBean
|
||||||
|
@SessionScoped
|
||||||
|
public class QuizBean implements Serializable {
|
||||||
|
private int currentProblem;
|
||||||
|
private int tries;
|
||||||
|
private String response = "";
|
||||||
|
private String correctAnswer;
|
||||||
|
|
||||||
|
// Here, we hardwire the problems. In a real application,
|
||||||
|
// they would come from a database
|
||||||
|
private ArrayList<Problem> problems = new ArrayList<Problem>(Arrays.asList(
|
||||||
|
new Problem(
|
||||||
|
"What trademarked slogan describes Java development? Write once, ...",
|
||||||
|
"run anywhere"),
|
||||||
|
new Problem(
|
||||||
|
"What are the first 4 bytes of every class file (in hexadecimal)?",
|
||||||
|
"CAFEBABE"),
|
||||||
|
new Problem(
|
||||||
|
"What does this statement print? System.out.println(1+\"2\");",
|
||||||
|
"12"),
|
||||||
|
new Problem(
|
||||||
|
"Which Java keyword is used to define a subclass?",
|
||||||
|
"extends"),
|
||||||
|
new Problem(
|
||||||
|
"What was the original name of the Java programming language?",
|
||||||
|
"Oak"),
|
||||||
|
new Problem(
|
||||||
|
"Which java.util class describes a point in time?",
|
||||||
|
"Date")));
|
||||||
|
|
||||||
|
private int[] scores = new int[problems.size()];
|
||||||
|
|
||||||
|
public String getQuestion() {
|
||||||
|
return problems.get(currentProblem).getQuestion();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAnswer() { return correctAnswer; }
|
||||||
|
|
||||||
|
public int getScore() {
|
||||||
|
int score = 0;
|
||||||
|
for (int s : scores) score += s;
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResponse() { return response; }
|
||||||
|
public void setResponse(String newValue) { response = newValue; }
|
||||||
|
|
||||||
|
public int getCurrentProblem() { return currentProblem; }
|
||||||
|
public void setCurrentProblem(int newValue) { currentProblem = newValue; }
|
||||||
|
|
||||||
|
public String getSkipOutcome() {
|
||||||
|
if (currentProblem < problems.size() - 1) return "index";
|
||||||
|
else return "done";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String answerAction() {
|
||||||
|
tries++;
|
||||||
|
if (problems.get(currentProblem).isCorrect(response)) {
|
||||||
|
scores[currentProblem] = 1;
|
||||||
|
nextProblem();
|
||||||
|
if (currentProblem == problems.size()) return "done";
|
||||||
|
else return "success";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
scores[currentProblem] = 0;
|
||||||
|
if (tries == 1) return "again";
|
||||||
|
else {
|
||||||
|
nextProblem();
|
||||||
|
if (currentProblem == problems.size()) return "done";
|
||||||
|
else return "failure";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String startOverAction() {
|
||||||
|
Collections.shuffle(problems);
|
||||||
|
currentProblem = 0;
|
||||||
|
for (int i = 0; i < scores.length; i++)
|
||||||
|
scores[i] = 0;
|
||||||
|
tries = 0;
|
||||||
|
response = "";
|
||||||
|
return "startOver";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextProblem() {
|
||||||
|
correctAnswer = problems.get(currentProblem).getAnswer();
|
||||||
|
currentProblem++;
|
||||||
|
tries = 0;
|
||||||
|
response = "";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
title=A Java Trivia Quiz
|
||||||
|
checkAnswer=Check Answer
|
||||||
|
startOver=Start over
|
||||||
|
correct=Congratulations, that is correct.
|
||||||
|
notCorrect=Sorry, that was not correct. Please try again!
|
||||||
|
stillNotCorrect=Sorry, that was still not correct.
|
||||||
|
correctAnswer=The correct answer was: {0}.
|
||||||
|
score=Your score is {0}.
|
||||||
|
nextProblem=Here is your next problem.
|
||||||
|
thankYou=Thank you for taking the quiz.
|
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<faces-config 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-facesconfig_2_0.xsd"
|
||||||
|
version="2.0">
|
||||||
|
<navigation-rule>
|
||||||
|
<navigation-case>
|
||||||
|
<from-outcome>startOver</from-outcome>
|
||||||
|
<to-view-id>/index.xhtml</to-view-id>
|
||||||
|
</navigation-case>
|
||||||
|
</navigation-rule>
|
||||||
|
<navigation-rule>
|
||||||
|
<from-view-id>/again.xhtml</from-view-id>
|
||||||
|
<navigation-case>
|
||||||
|
<from-outcome>failure</from-outcome>
|
||||||
|
<to-view-id>/failure.xhtml</to-view-id>
|
||||||
|
</navigation-case>
|
||||||
|
</navigation-rule>
|
||||||
|
<navigation-rule>
|
||||||
|
<navigation-case>
|
||||||
|
<from-outcome>failure</from-outcome>
|
||||||
|
<to-view-id>/again.xhtml</to-view-id>
|
||||||
|
</navigation-case>
|
||||||
|
</navigation-rule>
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<resource-bundle>
|
||||||
|
<base-name>com.corejsf.messages</base-name>
|
||||||
|
<var>msgs</var>
|
||||||
|
</resource-bundle>
|
||||||
|
</application>
|
||||||
|
</faces-config>
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5">
|
||||||
|
<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>/faces/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>faces/index.xhtml</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
<context-param>
|
||||||
|
<param-name>javax.faces.PROJECT_STAGE</param-name>
|
||||||
|
<param-value>Development</param-value>
|
||||||
|
</context-param>
|
||||||
|
</web-app>
|
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>#{msgs.notCorrect}</p>
|
||||||
|
<p>#{quizBean.question}</p>
|
||||||
|
<p><h:inputText value="#{quizBean.response}"/></p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.checkAnswer}"
|
||||||
|
action="#{quizBean.answerAction}"/>
|
||||||
|
</p>
|
||||||
|
<p><h:link outcome="#{quizBean.skipOutcome}" value="Skip">
|
||||||
|
<f:param name="q" value="#{quizBean.currentProblem + 1}"/>
|
||||||
|
</h:link>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>#{msgs.thankYou}
|
||||||
|
<h:outputFormat value="#{msgs.score}">
|
||||||
|
<f:param value="#{quizBean.score}"/>
|
||||||
|
</h:outputFormat>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.startOver}"
|
||||||
|
action="#{quizBean.startOverAction}"/>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>
|
||||||
|
#{msgs.stillNotCorrect}
|
||||||
|
<h:outputFormat value="#{msgs.correctAnswer}">
|
||||||
|
<f:param value="#{quizBean.answer}"/>
|
||||||
|
</h:outputFormat>
|
||||||
|
</p>
|
||||||
|
<p>#{msgs.nextProblem}</p>
|
||||||
|
<p>#{quizBean.question}</p>
|
||||||
|
<p>
|
||||||
|
<h:inputText value="#{quizBean.response}"/>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.checkAnswer}"
|
||||||
|
action="#{quizBean.answerAction}"/>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<h:link outcome="#{quizBean.skipOutcome}" value="Skip">
|
||||||
|
<f:param name="q" value="#{quizBean.currentProblem + 1}"/>
|
||||||
|
</h:link>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<f:metadata>
|
||||||
|
<f:viewParam name="q" value="#{quizBean.currentProblem}"/>
|
||||||
|
</f:metadata>
|
||||||
|
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>#{quizBean.question}</p>
|
||||||
|
<p><h:inputText value="#{quizBean.response}"/></p>
|
||||||
|
<p><h:commandButton value="#{msgs.checkAnswer}"
|
||||||
|
action="#{quizBean.answerAction}"/></p>
|
||||||
|
<p><h:link outcome="#{quizBean.skipOutcome}" value="Skip">
|
||||||
|
<f:param name="q" value="#{quizBean.currentProblem + 1}"/>
|
||||||
|
</h:link>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>
|
||||||
|
#{msgs.correct}
|
||||||
|
<h:outputFormat value="#{msgs.score}">
|
||||||
|
<f:param value="#{quizBean.score}"/>
|
||||||
|
</h:outputFormat>
|
||||||
|
</p>
|
||||||
|
<p>#{msgs.nextProblem}</p>
|
||||||
|
<p>#{quizBean.question}</p>
|
||||||
|
<p><h:inputText value="#{quizBean.response}"/></p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.checkAnswer}"
|
||||||
|
action="#{quizBean.answerAction}"/>
|
||||||
|
</p>
|
||||||
|
<p><h:link outcome="#{quizBean.skipOutcome}" value="Skip">
|
||||||
|
<f:param name="q" value="#{quizBean.currentProblem + 1}"/>
|
||||||
|
</h:link>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
Binary file not shown.
@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- You may freely edit this file. See commented blocks below for -->
|
||||||
|
<!-- some examples of how to customize the build. -->
|
||||||
|
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||||
|
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||||
|
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||||
|
<!-- the Compile on Save feature is turned off for the project. -->
|
||||||
|
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||||
|
<!-- in the project's Project Properties dialog box.-->
|
||||||
|
<project name="ch03-javaquiz" default="default" basedir=".">
|
||||||
|
<description>Builds, tests, and runs the project ch03-javaquiz.</description>
|
||||||
|
<import file="nbproject/build-impl.xml"/>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
There exist several targets which are by default empty and which can be
|
||||||
|
used for execution of your tasks. These targets are usually executed
|
||||||
|
before and after some main targets. They are:
|
||||||
|
|
||||||
|
-pre-init: called before initialization of project properties
|
||||||
|
-post-init: called after initialization of project properties
|
||||||
|
-pre-compile: called before javac compilation
|
||||||
|
-post-compile: called after javac compilation
|
||||||
|
-pre-compile-single: called before javac compilation of single file
|
||||||
|
-post-compile-single: called after javac compilation of single file
|
||||||
|
-pre-compile-test: called before javac compilation of JUnit tests
|
||||||
|
-post-compile-test: called after javac compilation of JUnit tests
|
||||||
|
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||||
|
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||||
|
-pre-dist: called before archive building
|
||||||
|
-post-dist: called after archive building
|
||||||
|
-post-clean: called after cleaning build products
|
||||||
|
-pre-run-deploy: called before deploying
|
||||||
|
-post-run-deploy: called after deploying
|
||||||
|
|
||||||
|
Example of pluging an obfuscator after the compilation could look like
|
||||||
|
|
||||||
|
<target name="-post-compile">
|
||||||
|
<obfuscate>
|
||||||
|
<fileset dir="${build.classes.dir}"/>
|
||||||
|
</obfuscate>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
For list of available properties check the imported
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
|
||||||
|
Other way how to customize the build is by overriding existing main targets.
|
||||||
|
The target of interest are:
|
||||||
|
|
||||||
|
init-macrodef-javac: defines macro for javac compilation
|
||||||
|
init-macrodef-junit: defines macro for junit execution
|
||||||
|
init-macrodef-debug: defines macro for class debugging
|
||||||
|
do-dist: archive building
|
||||||
|
run: execution of project
|
||||||
|
javadoc-build: javadoc generation
|
||||||
|
|
||||||
|
Example of overriding the target for project execution could look like
|
||||||
|
|
||||||
|
<target name="run" depends="<PROJNAME>-impl.jar">
|
||||||
|
<exec dir="bin" executable="launcher.exe">
|
||||||
|
<arg file="${dist.jar}"/>
|
||||||
|
</exec>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
Notice that overridden target depends on jar target and not only on
|
||||||
|
compile target as regular run target does. Again, for list of available
|
||||||
|
properties which you can use check the target you are overriding in
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
-->
|
||||||
|
</project>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,22 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class Problem implements Serializable {
|
||||||
|
private String question;
|
||||||
|
private String answer;
|
||||||
|
|
||||||
|
public Problem(String question, String answer) {
|
||||||
|
this.question = question;
|
||||||
|
this.answer = answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQuestion() { return question; }
|
||||||
|
|
||||||
|
public String getAnswer() { return answer; }
|
||||||
|
|
||||||
|
// override for more sophisticated checking
|
||||||
|
public boolean isCorrect(String response) {
|
||||||
|
return response.trim().equalsIgnoreCase(answer);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
// or import javax.faces.bean.ManagedBean;
|
||||||
|
import javax.enterprise.context.SessionScoped;
|
||||||
|
// or import javax.faces.bean.SessionScoped;
|
||||||
|
|
||||||
|
@Named // or @ManagedBean
|
||||||
|
@SessionScoped
|
||||||
|
public class QuizBean implements Serializable {
|
||||||
|
private int currentProblem;
|
||||||
|
private int tries;
|
||||||
|
private int score;
|
||||||
|
private String response = "";
|
||||||
|
private String correctAnswer;
|
||||||
|
|
||||||
|
// Here, we hardwire the problems. In a real application,
|
||||||
|
// they would come from a database
|
||||||
|
private ArrayList<Problem> problems = new ArrayList<Problem>(Arrays.asList(
|
||||||
|
new Problem(
|
||||||
|
"What trademarked slogan describes Java development? Write once, ...",
|
||||||
|
"run anywhere"),
|
||||||
|
new Problem(
|
||||||
|
"What are the first 4 bytes of every class file (in hexadecimal)?",
|
||||||
|
"CAFEBABE"),
|
||||||
|
new Problem(
|
||||||
|
"What does this statement print? System.out.println(1+\"2\");",
|
||||||
|
"12"),
|
||||||
|
new Problem(
|
||||||
|
"Which Java keyword is used to define a subclass?",
|
||||||
|
"extends"),
|
||||||
|
new Problem(
|
||||||
|
"What was the original name of the Java programming language?",
|
||||||
|
"Oak"),
|
||||||
|
new Problem(
|
||||||
|
"Which java.util class describes a point in time?",
|
||||||
|
"Date")));
|
||||||
|
|
||||||
|
public String getQuestion() { return problems.get(currentProblem).getQuestion(); }
|
||||||
|
|
||||||
|
public String getAnswer() { return correctAnswer; }
|
||||||
|
|
||||||
|
public int getScore() { return score; }
|
||||||
|
|
||||||
|
public String getResponse() { return response; }
|
||||||
|
public void setResponse(String newValue) { response = newValue; }
|
||||||
|
|
||||||
|
public String answerAction() {
|
||||||
|
tries++;
|
||||||
|
if (problems.get(currentProblem).isCorrect(response)) {
|
||||||
|
score++;
|
||||||
|
nextProblem();
|
||||||
|
if (currentProblem == problems.size()) return "done";
|
||||||
|
else return "success";
|
||||||
|
}
|
||||||
|
else if (tries == 1) return "again";
|
||||||
|
else {
|
||||||
|
nextProblem();
|
||||||
|
if (currentProblem == problems.size()) return "done";
|
||||||
|
else return "failure";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String startOverAction() {
|
||||||
|
Collections.shuffle(problems);
|
||||||
|
currentProblem = 0;
|
||||||
|
score = 0;
|
||||||
|
tries = 0;
|
||||||
|
response = "";
|
||||||
|
return "startOver";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextProblem() {
|
||||||
|
correctAnswer = problems.get(currentProblem).getAnswer();
|
||||||
|
currentProblem++;
|
||||||
|
tries = 0;
|
||||||
|
response = "";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
title=A Java Trivia Quiz
|
||||||
|
checkAnswer=Check Answer
|
||||||
|
startOver=Start over
|
||||||
|
correct=Congratulations, that is correct.
|
||||||
|
notCorrect=Sorry, that was not correct. Please try again!
|
||||||
|
stillNotCorrect=Sorry, that was still not correct.
|
||||||
|
correctAnswer=The correct answer was: {0}.
|
||||||
|
score=Your score is {0}.
|
||||||
|
nextProblem=Here is your next problem.
|
||||||
|
thankYou=Thank you for taking the quiz.
|
Binary file not shown.
@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<faces-config 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-facesconfig_2_0.xsd"
|
||||||
|
version="2.0">
|
||||||
|
<navigation-rule>
|
||||||
|
<navigation-case>
|
||||||
|
<from-outcome>startOver</from-outcome>
|
||||||
|
<to-view-id>/index.xhtml</to-view-id>
|
||||||
|
</navigation-case>
|
||||||
|
</navigation-rule>
|
||||||
|
<navigation-rule>
|
||||||
|
<from-view-id>/again.xhtml</from-view-id>
|
||||||
|
<navigation-case>
|
||||||
|
<from-outcome>failure</from-outcome>
|
||||||
|
<to-view-id>/failure.xhtml</to-view-id>
|
||||||
|
</navigation-case>
|
||||||
|
</navigation-rule>
|
||||||
|
<navigation-rule>
|
||||||
|
<navigation-case>
|
||||||
|
<from-outcome>failure</from-outcome>
|
||||||
|
<to-view-id>/again.xhtml</to-view-id>
|
||||||
|
</navigation-case>
|
||||||
|
</navigation-rule>
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<resource-bundle>
|
||||||
|
<base-name>com.corejsf.messages</base-name>
|
||||||
|
<var>msgs</var>
|
||||||
|
</resource-bundle>
|
||||||
|
</application>
|
||||||
|
</faces-config>
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5">
|
||||||
|
<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>/faces/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>faces/index.xhtml</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
<context-param>
|
||||||
|
<param-name>javax.faces.PROJECT_STAGE</param-name>
|
||||||
|
<param-value>Development</param-value>
|
||||||
|
</context-param>
|
||||||
|
</web-app>
|
@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}"</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>#{msgs.notCorrect}</p>
|
||||||
|
<p>#{quizBean.question}</p>
|
||||||
|
<p><h:inputText value="#{quizBean.response}"/></p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.checkAnswer}"
|
||||||
|
action="#{quizBean.answerAction}"/>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>
|
||||||
|
#{msgs.thankYou}
|
||||||
|
<h:outputFormat value="#{msgs.score}">
|
||||||
|
<f:param value="#{quizBean.score}"/>
|
||||||
|
</h:outputFormat>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.startOver}"
|
||||||
|
action="#{quizBean.startOverAction}"/>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>
|
||||||
|
#{msgs.stillNotCorrect}"
|
||||||
|
<h:outputFormat value="#{msgs.correctAnswer}">
|
||||||
|
<f:param value="#{quizBean.answer}"/>
|
||||||
|
</h:outputFormat>
|
||||||
|
</p>
|
||||||
|
<p>#{msgs.nextProblem}</p>
|
||||||
|
<p>#{quizBean.question}</p>
|
||||||
|
<p><h:inputText value="#{quizBean.response}"/></p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.checkAnswer}"
|
||||||
|
action="#{quizBean.answerAction}"/>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>#{quizBean.question}"</p>
|
||||||
|
<p><h:inputText value="#{quizBean.response}"/></p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.checkAnswer}"
|
||||||
|
action="#{quizBean.answerAction}"/>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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:f="http://java.sun.com/jsf/core"
|
||||||
|
xmlns:h="http://java.sun.com/jsf/html">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.title}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<p>
|
||||||
|
#{msgs.correct}
|
||||||
|
<h:outputFormat value="#{msgs.score}">
|
||||||
|
<f:param value="#{quizBean.score}"/>
|
||||||
|
</h:outputFormat>
|
||||||
|
</p>
|
||||||
|
<p>#{msgs.nextProblem}</p>
|
||||||
|
<p>#{quizBean.question}</p>
|
||||||
|
<p><h:inputText value="#{quizBean.response}"/></p>
|
||||||
|
<p>
|
||||||
|
<h:commandButton value="#{msgs.checkAnswer}"
|
||||||
|
action="#{quizBean.answerAction}"/>
|
||||||
|
</p>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,26 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
// or import javax.faces.bean.ManagedBean;
|
||||||
|
import javax.enterprise.context.SessionScoped;
|
||||||
|
// or import javax.faces.bean.SessionScoped;
|
||||||
|
import javax.faces.context.FacesContext;
|
||||||
|
|
||||||
|
@Named // or @ManagedBean
|
||||||
|
@SessionScoped
|
||||||
|
public class LocaleChanger implements Serializable {
|
||||||
|
public String germanAction() {
|
||||||
|
FacesContext context = FacesContext.getCurrentInstance();
|
||||||
|
context.getViewRoot().setLocale(Locale.GERMAN);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String englishAction() {
|
||||||
|
FacesContext context = FacesContext.getCurrentInstance();
|
||||||
|
context.getViewRoot().setLocale(Locale.ENGLISH);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.corejsf;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
// or import javax.faces.bean.ManagedBean;
|
||||||
|
import javax.enterprise.context.SessionScoped;
|
||||||
|
// or import javax.faces.bean.SessionScoped;
|
||||||
|
|
||||||
|
@Named("user") // or @ManagedBean(name="user")
|
||||||
|
@SessionScoped
|
||||||
|
public class UserBean implements Serializable {
|
||||||
|
private String name;
|
||||||
|
private String password;
|
||||||
|
private String aboutYourself;
|
||||||
|
|
||||||
|
public String getName() { return name; }
|
||||||
|
public void setName(String newValue) { name = newValue; }
|
||||||
|
|
||||||
|
public String getPassword() { return password; }
|
||||||
|
public void setPassword(String newValue) { password = newValue; }
|
||||||
|
|
||||||
|
public String getAboutYourself() { return aboutYourself; }
|
||||||
|
public void setAboutYourself(String newValue) { aboutYourself = newValue; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
indexWindowTitle=Using Command Links
|
||||||
|
thankYouWindowTitle=Thank you for submitting your information
|
||||||
|
thankYouPageTitle=Thank you!
|
||||||
|
indexPageTitle=Please enter the following personal information
|
||||||
|
namePrompt=Name:
|
||||||
|
passwordPrompt=Password:
|
||||||
|
tellUsPrompt=Please tell us about yourself:
|
||||||
|
aboutYourselfPrompt=Some information about you:
|
||||||
|
submitPrompt=Submit your information
|
@ -0,0 +1,10 @@
|
|||||||
|
indexWindowTitle=Ein Beispiel f\u00fcr Textfelder und Textgebiete
|
||||||
|
thankYouWindowTitle=Vielen Dank f\u00fcr Ihre Informationen
|
||||||
|
thankYouPageTitle=Vielen Dank!
|
||||||
|
indexPageTitle=Bitte geben Sie die folgenden pers\u00f6nlichen Daten ein
|
||||||
|
namePrompt=Name:
|
||||||
|
passwordPrompt=Pa\u00dfwort:
|
||||||
|
tellUsPrompt=Bitte erz\u00e4hlen Sie etwas \u00fcber sich:
|
||||||
|
aboutYourselfPrompt=Ihre pers\u00f6nlichen Daten:
|
||||||
|
submitPrompt=Daten absenden
|
||||||
|
usingCommandLinks=Kommando-Links benutzen
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<faces-config 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-facesconfig_2_0.xsd"
|
||||||
|
version="2.0">
|
||||||
|
<application>
|
||||||
|
<resource-bundle>
|
||||||
|
<base-name>com.corejsf.messages</base-name>
|
||||||
|
<var>msgs</var>
|
||||||
|
</resource-bundle>
|
||||||
|
</application>
|
||||||
|
</faces-config>
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5">
|
||||||
|
<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>/faces/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>faces/index.xhtml</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
<context-param>
|
||||||
|
<param-name>javax.faces.PROJECT_STAGE</param-name>
|
||||||
|
<param-value>Development</param-value>
|
||||||
|
</context-param>
|
||||||
|
</web-app>
|
@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.indexWindowTitle}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<h:commandLink action="#{localeChanger.germanAction}">
|
||||||
|
<h:graphicImage library="images" name="de_flag.gif"
|
||||||
|
style="border: 0px; margin-right: 1em;"/>
|
||||||
|
</h:commandLink>
|
||||||
|
<h:commandLink action="#{localeChanger.englishAction}">
|
||||||
|
<h:graphicImage library="images"
|
||||||
|
name="en_flag.gif" style="border: 0px"/>
|
||||||
|
</h:commandLink>
|
||||||
|
<p><h:outputText value="#{msgs.indexPageTitle}"
|
||||||
|
style="font-style: italic; font-size: 1.3em"/></p>
|
||||||
|
<h:panelGrid columns="2">
|
||||||
|
#{msgs.namePrompt}
|
||||||
|
<h:inputText value="#{user.name}"/>
|
||||||
|
#{msgs.passwordPrompt}
|
||||||
|
<h:inputSecret value="#{user.password}"/>
|
||||||
|
#{msgs.tellUsPrompt}
|
||||||
|
<h:inputTextarea value="#{user.aboutYourself}" rows="5" cols="35"/>
|
||||||
|
</h:panelGrid>
|
||||||
|
<h:commandButton value="#{msgs.submitPrompt}" action="thankYou"/>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 191 B |
Binary file not shown.
After Width: | Height: | Size: 528 B |
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.thankYouWindowTitle}</title>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:outputText value="#{msgs.namePrompt}" style="font-style: italic"/>
|
||||||
|
#{user.name}
|
||||||
|
<br/>
|
||||||
|
<h:outputText value="#{msgs.aboutYourselfPrompt}" style="font-style: italic"/>
|
||||||
|
<br/>
|
||||||
|
<pre>#{user.aboutYourself}</pre>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
|
|||||||
|
windowTitle=Accessing Form Elements with JavaScript
|
||||||
|
namePrompt=Name:
|
||||||
|
passwordPrompt=Password:
|
||||||
|
confirmPasswordPrompt=Confirm Password:
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<faces-config 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-facesconfig_2_0.xsd"
|
||||||
|
version="2.0">
|
||||||
|
<application>
|
||||||
|
<resource-bundle>
|
||||||
|
<base-name>com.corejsf.messages</base-name>
|
||||||
|
<var>msgs</var>
|
||||||
|
</resource-bundle>
|
||||||
|
</application>
|
||||||
|
</faces-config>
|
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://java.sun.com/xml/ns/javaee"
|
||||||
|
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||||
|
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||||
|
version="2.5">
|
||||||
|
<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>/faces/*</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
|
<welcome-file-list>
|
||||||
|
<welcome-file>faces/index.xhtml</welcome-file>
|
||||||
|
</welcome-file-list>
|
||||||
|
<context-param>
|
||||||
|
<param-name>javax.faces.PROJECT_STAGE</param-name>
|
||||||
|
<param-value>Development</param-value>
|
||||||
|
</context-param>
|
||||||
|
</web-app>
|
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!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">
|
||||||
|
<h:head>
|
||||||
|
<title>#{msgs.windowTitle}</title>
|
||||||
|
<h:outputStylesheet library="css" name="styles.css"/>
|
||||||
|
<h:outputScript library="javascript" name="checkPassword.js"/>
|
||||||
|
</h:head>
|
||||||
|
<h:body>
|
||||||
|
<h:form>
|
||||||
|
<h:panelGrid columns="2" columnClasses="evenColumns, oddColumns">
|
||||||
|
#{msgs.namePrompt}
|
||||||
|
<h:inputText/>
|
||||||
|
#{msgs.passwordPrompt}
|
||||||
|
<h:inputSecret id="password"/>
|
||||||
|
#{msgs.confirmPasswordPrompt}
|
||||||
|
<h:inputSecret id="passwordConfirm"/>
|
||||||
|
</h:panelGrid>
|
||||||
|
<h:commandButton type="button" value="Submit Form"
|
||||||
|
onclick="checkPassword(this.form)"/>
|
||||||
|
</h:form>
|
||||||
|
</h:body>
|
||||||
|
</html>
|
@ -0,0 +1,7 @@
|
|||||||
|
.evenColumns {
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
.oddColumns {
|
||||||
|
padding-left: 1em;
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
function checkPassword(form) {
|
||||||
|
var password = form[form.id + ":password"].value;
|
||||||
|
var passwordConfirm = form[form.id + ":passwordConfirm"].value;
|
||||||
|
|
||||||
|
if(password == passwordConfirm)
|
||||||
|
form.submit();
|
||||||
|
else
|
||||||
|
alert("Password and password confirm fields don't match");
|
||||||
|
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user