[corejsf~subversion:164] ...
- From: cayhorstmann@kenai.com
- To: commits@corejsf.kenai.com
- Subject: [corejsf~subversion:164] ...
- Date: Tue, 2 Feb 2010 04:46:59 +0000
Project: corejsf
Repository: subversion
Revision: 164
Author: cayhorstmann
Date: 2010-02-02 04:46:51 UTC
Link:
Log Message:
------------
...
Revisions:
----------
164
Added Paths:
------------
ch09/composite-login/web/resources/util/login.xhtml
ch09/composite-login/web/resources/util/login.properties
ch09/composite-login/src/java/com/corejsf/User.java
ch09/composite-login/web/register.xhtml
ch09/composite-login/web/WEB-INF
ch09/composite-login/web/resources/util/login.js
ch09/composite-login
ch09/composite-login/src/java/com
ch09/composite-login/web/WEB-INF/beans.xml
ch09/composite-login/web
ch09/composite-login/web/resources/images/back.png
ch09/composite-login/web/resources/images
ch09/composite-login/src/java/com/corejsf
ch09/composite-login/web/WEB-INF/sun-web.xml
ch09/composite-login/web/resources/util/icon.xhtml
ch09/composite-login/web/resources/css
ch09/composite-login/src/java
ch09/composite-login/web/resources/css/styles.css
ch09/composite-login/web/resources/util
ch09/composite-login/src/java/com/corejsf/messages.properties
ch09/composite-login/web/WEB-INF/web.xml
ch09/composite-login/src
ch09/composite-login/src/java/com/corejsf/PasswordValidator.java
ch09/composite-login/src/java/com/corejsf/Registrar.java
ch09/composite-login/web/welcome.xhtml
ch09/composite-login/web/resources
ch09/composite-login/src/java/com/corejsf/LoginActionListener.java
ch09/composite-login/web/index.xhtml
ch09/composite-login/web/WEB-INF/faces-config.xml
Diffs:
------
Index: ch09/composite-login/src/java/com/corejsf/Registrar.java
===================================================================
--- ch09/composite-login/src/java/com/corejsf/Registrar.java (revision 0)
+++ ch09/composite-login/src/java/com/corejsf/Registrar.java (revision 164)
@@ -0,0 +1,24 @@
+package com.corejsf;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Registrar {
+
+ private static List<User> registeredUsers = new ArrayList<User>();
+ static {
+ registeredUsers.add(new User("Hiro", "secret"));
+ }
+
+ public static void register(String name, String password) {
+ registeredUsers.add(new User(name, password));
+ }
+
+ public static boolean isRegistered(String name, String password) {
+ for (User user : registeredUsers) {
+ if (user.getName().equals(name) &&
user.getPassword().equals(password))
+ return true;
+ }
+ return false;
+ }
+}
Index: ch09/composite-login/src/java/com/corejsf/messages.properties
===================================================================
--- ch09/composite-login/src/java/com/corejsf/messages.properties
(revision 0)
+++ ch09/composite-login/src/java/com/corejsf/messages.properties
(revision 164)
@@ -0,0 +1,19 @@
+loginWindowTitle=Log in
+loginHeading=Log in
+namePrompt=Name
+passwordPrompt=Password
+loginPrompt=Please log in
+welcomeGreeting=Welcome,
+loginButtonText=Log In
+welcomeHeading=Welcome
+streetAddress=address
+logoutButtonText=Log out
+registerLinkText=Register...
+registerGreeting=Registration
+registerHeading=Please register
+passwordVerifyPrompt=Verify password
+cancelButtonText=Cancel
+registerButtonText=Register
+
+javax.faces.validator.LengthValidator.MAXIMUM=Too many characters. You can
only type {0} characters in this field.
+javax.faces.validator.LengthValidator.MINIMUM=Not enough characters. You
must enter at least {0} characters in this field.
\ No newline at end of file
Index: ch09/composite-login/src/java/com/corejsf/PasswordValidator.java
===================================================================
--- ch09/composite-login/src/java/com/corejsf/PasswordValidator.java
(revision 0)
+++ ch09/composite-login/src/java/com/corejsf/PasswordValidator.java
(revision 164)
@@ -0,0 +1,19 @@
+package com.corejsf;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.FacesValidator;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+@FacesValidator("com.corejsf.Password")
+public class PasswordValidator implements Validator {
+ public void validate(FacesContext context, UIComponent component, Object
value)
+ throws ValidatorException {
+ String pwd = (String)value;
+ if (pwd.contains("@")) {
+ throw new ValidatorException(new FacesMessage("Passwords cannot
contain @"));
+ }
+ }
+}
\ No newline at end of file
Index: ch09/composite-login/src/java/com/corejsf/LoginActionListener.java
===================================================================
--- ch09/composite-login/src/java/com/corejsf/LoginActionListener.java
(revision 0)
+++ ch09/composite-login/src/java/com/corejsf/LoginActionListener.java
(revision 164)
@@ -0,0 +1,25 @@
+package com.corejsf;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.component.UIInput;
+import javax.faces.context.FacesContext;
+import javax.faces.event.AbortProcessingException;
+import javax.faces.event.ActionEvent;
+import javax.faces.event.ActionListener;
+
+public class LoginActionListener implements ActionListener {
+ public void processAction(ActionEvent event) throws
AbortProcessingException {
+ UIComponent container = event.getComponent().getNamingContainer();
+ String name = (String) ((UIInput)
+ container.findComponent("form:name")).getValue();
+ String pwd = (String) ((UIInput)
+ container.findComponent("form:password")).getValue();
+ if (Registrar.isRegistered(name, pwd)) return;
+
+ FacesContext context = FacesContext.getCurrentInstance();
+ context.addMessage(container.getClientId(),
+ new FacesMessage("Name and password are invalid. Please try
again."));
+ throw new AbortProcessingException("Invalid credentials");
+ }
+}
Index: ch09/composite-login/src/java/com/corejsf/User.java
===================================================================
--- ch09/composite-login/src/java/com/corejsf/User.java (revision 0)
+++ ch09/composite-login/src/java/com/corejsf/User.java (revision 164)
@@ -0,0 +1,40 @@
+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 // or @ManagedBean
+@SessionScoped
+public class User implements Serializable {
+ private String name;
+ private String password;
+
+ public User() { this("", ""); }
+ public User(String name, String password) {
+ this.name = name;
+ this.password = password;
+ }
+
+ public String getPassword() { return password; }
+ public void setPassword(String newValue) { password = newValue; }
+
+ public String getName() { return name; }
+ public void setName(String newValue) { name = newValue; }
+
+ public String register() {
+ Registrar.register(name, password);
+ return "welcome";
+ }
+
+ public String login() {
+ return "welcome";
+ }
+
+ public String logout() {
+ name = password = "";
+ return "index";
+ }
+}
\ No newline at end of file
Index: ch09/composite-login/web/register.xhtml
===================================================================
--- ch09/composite-login/web/register.xhtml (revision 0)
+++ ch09/composite-login/web/register.xhtml (revision 164)
@@ -0,0 +1,27 @@
+<!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.registerHeading}</title>
+ <h:outputStylesheet library="css" name="styles.css" />
+ </h:head>
+ <h:body>
+ <h:form>
+ <p><h:outputText value="#{msgs.registerHeading}"
styleClass="prompt"/></p>
+ <h:panelGrid columns="2">
+ #{msgs.namePrompt}
+ <h:inputText id="name" value="#{user.name}"/>
+
+ #{msgs.passwordPrompt}
+ <h:inputSecret id="password" value="#{user.password}" size="8"/>
+ </h:panelGrid>
+
+ <p>
+ <h:commandButton value="#{msgs.registerButtonText}"
+ action="#{user.register}"/>
+ <h:commandButton value="#{msgs.cancelButtonText}" action="index"/>
+ </p>
+ </h:form>
+ </h:body>
+</html>
\ No newline at end of file
Index: ch09/composite-login/web/index.xhtml
===================================================================
--- ch09/composite-login/web/index.xhtml (revision 0)
+++ ch09/composite-login/web/index.xhtml (revision 164)
@@ -0,0 +1,38 @@
+<!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"
+ xmlns:util="http://java.sun.com/jsf/composite/util"
+ xmlns:ui="http://java.sun.com/jsf/facelets">
+ <h:head>
+ <title>#{msgs.loginHeading}</title>
+ <h:outputStylesheet library="css" name="styles.css" />
+ </h:head>
+ <h:body>
+ <util:login namePrompt="#{msgs.namePrompt}"
+ passwordPrompt="#{msgs.passwordPrompt}"
+ name="#{user.name}"
+ password="#{user.password}"
+ loginAction="#{user.login}"
+ loginButtonText="#{msgs.loginButtonText}">
+
+ <f:validateLength minimum="4" for="nameInput"/>
+ <f:validator validatorId="com.corejsf.Password"
for="passwordInput"/>
+ <f:actionListener type="com.corejsf.LoginActionListener"
for="loginButton"/>
+
+ <f:facet name="heading" styleClass="header">
+ <div class="prompt">#{msgs.loginPrompt}</div>
+ </f:facet>
+
+ <f:facet name="error" styleClass="error">
+ <h:messages layout="table" styleClass="error"/>
+ </f:facet>
+
+ <!-- Child component -->
+ <h:link outcome="register">#{msgs.registerLinkText}</h:link>
+
+ </util:login>
+ <ui:debug/>
+ </h:body>
+</html>
\ No newline at end of file
Index: ch09/composite-login/web/welcome.xhtml
===================================================================
--- ch09/composite-login/web/welcome.xhtml (revision 0)
+++ ch09/composite-login/web/welcome.xhtml (revision 164)
@@ -0,0 +1,17 @@
+<!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"
+ xmlns:util="http://java.sun.com/jsf/composite/util">
+ <h:head>
+ <title>#{msgs.welcomeHeading}</title>
+ <h:outputStylesheet library="css" name="styles.css" />
+ </h:head>
+ <h:body>
+ #{msgs.welcomeGreeting} #{user.name}
+
+ <util:icon image="#{resource['images:back.png']}"
+ actionMethod="#{user.logout}" style="border: thin solid
lightBlue"/>
+ </h:body>
+</html>
\ No newline at end of file
Index: ch09/composite-login/web/WEB-INF/sun-web.xml
===================================================================
--- ch09/composite-login/web/WEB-INF/sun-web.xml (revision 0)
+++ ch09/composite-login/web/WEB-INF/sun-web.xml (revision 164)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application
Server 9.0 Servlet 2.5//EN"
"http://www.sun.com/software/appserver/dtds/sun-web-app_2_5-0.dtd">
+<sun-web-app error-url="">
+ <context-root>/composite-login</context-root>
+ <class-loader delegate="true"/>
+ <jsp-config>
+ <property name="keepgenerated" value="true">
+ <description>Keep a copy of the generated servlet class' java
code.</description>
+ </property>
+ </jsp-config>
+</sun-web-app>
Index: ch09/composite-login/web/WEB-INF/faces-config.xml
===================================================================
--- ch09/composite-login/web/WEB-INF/faces-config.xml (revision 0)
+++ ch09/composite-login/web/WEB-INF/faces-config.xml (revision 164)
@@ -0,0 +1,18 @@
+<?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>
+
+ <message-bundle>
+ <base-name>com.corejsf.messages</base-name>
+ </message-bundle>
+
+ </application>
+</faces-config>
\ No newline at end of file
Index: ch09/composite-login/web/WEB-INF/beans.xml
===================================================================
Index: ch09/composite-login/web/WEB-INF/web.xml
===================================================================
--- ch09/composite-login/web/WEB-INF/web.xml (revision 0)
+++ ch09/composite-login/web/WEB-INF/web.xml (revision 164)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ version="2.5"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <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>
+
+ <context-param>
+ <param-name>javax.faces.PROJECT_STAGE</param-name>
+ <param-value>Development</param-value>
+ </context-param>
+
+ <welcome-file-list>
+ <welcome-file>faces/index.xhtml</welcome-file>
+ </welcome-file-list>
+</web-app>
\ No newline at end of file
Index: ch09/composite-login/web/resources/images/back.png
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes on: ch09/composite-login/web/resources/images/back.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Index: ch09/composite-login/web/resources/css/styles.css
===================================================================
--- ch09/composite-login/web/resources/css/styles.css (revision 0)
+++ ch09/composite-login/web/resources/css/styles.css (revision 164)
@@ -0,0 +1,32 @@
+body {
+ background: #fefeef;
+}
+
+.header {
+ padding: 20px;
+ margin-bottom: 10px;
+ background: #dddddd;
+ border: 1px solid #cccccc;
+ font-size: 1.4em;
+ font-style: italic;
+ font-family: Palatino;
+ right: 20px;
+ text-align: center;
+}
+
+.prompt {
+ font-size: 1.15em;
+ margin-left: 5px;
+ margin-top: 20px;
+ margin-bottom: 20px;
+ font-family: Palatino;
+}
+
+.error {
+ color: red;
+}
+
+.icon {
+ margin: 10px;
+ border: none;
+}
\ No newline at end of file
Index: ch09/composite-login/web/resources/util/icon.xhtml
===================================================================
--- ch09/composite-login/web/resources/util/icon.xhtml (revision 0)
+++ ch09/composite-login/web/resources/util/icon.xhtml (revision 164)
@@ -0,0 +1,28 @@
+<!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:composite="http://java.sun.com/jsf/composite">
+
+ <composite:interface>
+ <composite:attribute name="image" required="true" />
+ <composite:attribute name="doValidation" default="false" />
+ <composite:attribute name="styleClass" default="icon" />
+ <composite:attribute name="actionMethod"
+ method-signature="java.lang.String action()" />
+ </composite:interface>
+
+ <composite:implementation>
+ <h:form>
+ <h:commandLink action="#{cc.attrs.actionMethod}"
+ immediate="#{not cc.attrs.doValidation}">
+
+ <h:graphicImage url="#{cc.attrs.image}"
+ styleClass="#{cc.attrs.styleClass}" />
+
+ </h:commandLink>
+ </h:form>
+ </composite:implementation>
+
+</html>
\ No newline at end of file
Index: ch09/composite-login/web/resources/util/login.js
===================================================================
--- ch09/composite-login/web/resources/util/login.js (revision 0)
+++ ch09/composite-login/web/resources/util/login.js (revision 164)
@@ -0,0 +1,10 @@
+function checkForm(form, ccId) {
+ var name = form[ccId + ':form:name'].value;
+ var pwd = form[ccId + ':form:password'].value;
+
+ if (name == "" || pwd == "") {
+ alert("Please enter name and password.");
+ return false;
+ }
+ return true;
+}
\ No newline at end of file
Index: ch09/composite-login/web/resources/util/login.properties
===================================================================
--- ch09/composite-login/web/resources/util/login.properties (revision 0)
+++ ch09/composite-login/web/resources/util/login.properties (revision 164)
@@ -0,0 +1 @@
+footer=This advertising space is available. Call 555-1212.
\ No newline at end of file
Index: ch09/composite-login/web/resources/util/login.xhtml
===================================================================
--- ch09/composite-login/web/resources/util/login.xhtml (revision 0)
+++ ch09/composite-login/web/resources/util/login.xhtml (revision 164)
@@ -0,0 +1,65 @@
+<!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:composite="http://java.sun.com/jsf/composite">
+
+ <composite:interface>
+ <composite:editableValueHolder name="nameInput" targets="form:name"/>
+ <composite:editableValueHolder name="passwordInput"
targets="form:password"/>
+ <composite:editableValueHolder name="inputs"
+ targets="form:name form:password"/>
+ <composite:actionSource name="loginButton" targets="form:loginButton"/>
+
+ <composite:attribute name="name"/>
+ <composite:attribute name="password"/>
+
+ <composite:attribute name="namePrompt"/>
+ <composite:attribute name="passwordPrompt"/>
+
+ <composite:attribute name="loginValidate"
+ method-signature="void validateLogin(ComponentSystemEvent e)
+ throws javax.faces.event.AbortProcessingException"/>
+
+ <composite:attribute name="loginAction"
+ method-signature="java.lang.String action()"/>
+
+ <composite:facet name="heading"/>
+ <composite:facet name="error"/>
+ </composite:interface>
+
+ <composite:implementation>
+ <h:outputScript library="components/util" name="login.js"
target="head"/>
+ <h:form id="form" onsubmit="return checkForm(this, '#{cc.clientId}')">
+ <composite:renderFacet name="heading"/>
+ <h:panelGrid columns="2">
+ #{cc.attrs.namePrompt}
+ <h:panelGroup>
+ <h:inputText id="name" value="#{cc.attrs.name}"/>
+ <h:message for="name"/>
+ </h:panelGroup>
+
+ #{cc.attrs.passwordPrompt}
+
+ <h:panelGroup>
+ <h:inputSecret id="password" value="#{cc.attrs.password}"
size="8"/>
+ <h:message for="password"/>
+ </h:panelGroup>
+ </h:panelGrid>
+
+ <p>
+ <h:commandButton id="loginButton"
+ value="#{cc.attrs.loginButtonText}"
+ action="#{cc.attrs.loginAction}"/>
+ </p>
+
+ </h:form>
+
+ <composite:renderFacet name="error"/>
+
+ <p><composite:insertChildren/></p>
+
+ <p>#{cc.resourceBundleMap.footer}</p>
+ </composite:implementation>
+</html>
\ No newline at end of file
|
[corejsf~subversion:164] ... |
cayhorstmann | 02/02/2010 |





