diff --git a/jsf/pom.xml b/jsf/pom.xml new file mode 100644 index 0000000000..7b15cf9336 --- /dev/null +++ b/jsf/pom.xml @@ -0,0 +1,37 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + jsf + 0.1-SNAPSHOT + war + + + + com.sun.faces + mojarra-jsf-impl + 2.0.0-b04 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + + + + \ No newline at end of file diff --git a/jsf/src/main/java/com/baeldung/springintegration/controllers/RegistrationBean.java b/jsf/src/main/java/com/baeldung/springintegration/controllers/RegistrationBean.java new file mode 100644 index 0000000000..b2cd505bd7 --- /dev/null +++ b/jsf/src/main/java/com/baeldung/springintegration/controllers/RegistrationBean.java @@ -0,0 +1,95 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.springintegration.controllers; + +import com.baeldung.springintegration.dao.IUserManagementDAO; + +import javax.faces.bean.ManagedBean; +import javax.faces.bean.ManagedProperty; +import javax.faces.bean.ViewScoped; +import javax.faces.context.FacesContext; +import java.io.Serializable; +import java.util.logging.Logger; + +/** + * + * @author Tayo + */ +@ManagedBean(name = "registration") +@ViewScoped +public class RegistrationBean implements Serializable { + + @ManagedProperty(value = "#{userManagementDAO}") + transient private IUserManagementDAO theUserDao; + private String userName; + private String operationMessage; + private boolean operationStatus; + + /** + * Creates a new instance of RegistrationBean + */ + public RegistrationBean() { + } + + public String createNewUser() { + try { + Logger.getAnonymousLogger().info("Creating new user"); + FacesContext context = FacesContext.getCurrentInstance(); + operationStatus = theUserDao.createUser(userName); //DAO layer is used to register user using gathered data + context.isValidationFailed(); + if (operationStatus) { + + operationMessage = "User " + userName + " created"; + } + } catch (Exception ex) { + Logger.getAnonymousLogger().severe("Error registering new user "); + ex.printStackTrace(); + } + return null; + } + + public String returnHome() { + return "home"; + } + + /** + * @return the name + */ + public String getUserName() { + return userName; + } + + /** + * @param userName the name to set + */ + public void setUserName(String userName) { + this.userName = userName; + } + + /** + * @param theUserDao the theUserDao to set + */ + public void setTheUserDao(IUserManagementDAO theUserDao) { + this.theUserDao = theUserDao; + } + + public IUserManagementDAO getTheUserDao() { + return this.theUserDao; + } + + /** + * @return the operationMessage + */ + public String getOperationMessage() { + return operationMessage; + } + + /** + * @param operationMessage the operationMessage to set + */ + public void setOperationMessage(String operationMessage) { + this.operationMessage = operationMessage; + } +} diff --git a/jsf/src/main/java/com/baeldung/springintegration/dao/IUserManagementDAO.java b/jsf/src/main/java/com/baeldung/springintegration/dao/IUserManagementDAO.java new file mode 100644 index 0000000000..bfa50cc998 --- /dev/null +++ b/jsf/src/main/java/com/baeldung/springintegration/dao/IUserManagementDAO.java @@ -0,0 +1,18 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.springintegration.dao; + + +/** + * @author Tayo + */ +public abstract class IUserManagementDAO implements UserManagementDAO { + + + @Override + public abstract boolean createUser(String userName); + + +} diff --git a/jsf/src/main/java/com/baeldung/springintegration/dao/UserManagementDAO.java b/jsf/src/main/java/com/baeldung/springintegration/dao/UserManagementDAO.java new file mode 100644 index 0000000000..8ee8bb906f --- /dev/null +++ b/jsf/src/main/java/com/baeldung/springintegration/dao/UserManagementDAO.java @@ -0,0 +1,16 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.springintegration.dao; + + +/** + * @author Tayo + */ +public interface UserManagementDAO { + + public boolean createUser(String newUserData); + + +} diff --git a/jsf/src/main/java/com/baeldung/springintegration/dao/UserManagementDAOImpl.java b/jsf/src/main/java/com/baeldung/springintegration/dao/UserManagementDAOImpl.java new file mode 100644 index 0000000000..6bdcb57cfa --- /dev/null +++ b/jsf/src/main/java/com/baeldung/springintegration/dao/UserManagementDAOImpl.java @@ -0,0 +1,40 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.springintegration.dao; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.annotation.PostConstruct; + +/** + * @author Tayo + */ +public class UserManagementDAOImpl extends IUserManagementDAO { + + private List users; + + @PostConstruct + public void initUserList() { + users = new ArrayList(); + } + + @Override + public boolean createUser(String newUserData) { + if (newUserData != null) { + users.add(newUserData); + Logger.getAnonymousLogger().log(Level.INFO, "User {0} successfully created", newUserData); + return true; + } else { + return false; + } + } + + public UserManagementDAOImpl() { + } + + +} diff --git a/jsf/src/main/java/com/baeldung/springintegration/resources/constraints.properties b/jsf/src/main/java/com/baeldung/springintegration/resources/constraints.properties new file mode 100644 index 0000000000..00b6c57a88 --- /dev/null +++ b/jsf/src/main/java/com/baeldung/springintegration/resources/constraints.properties @@ -0,0 +1,10 @@ +userName.maxLength = 8 +userName.minLength = 4 +password.minLength = 8 +password.maxLength = 12 +zip.length = 5 +password.regexp = ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$ +safetext.regexp = ^[a-zA-Z0-9 .-]+$ +zip.regexp = ^\d{5} +security.salt = G0d$3nd +birthdate.format = MM dd yyyy \ No newline at end of file diff --git a/jsf/src/main/java/com/baeldung/springintegration/resources/messages.properties b/jsf/src/main/java/com/baeldung/springintegration/resources/messages.properties new file mode 100644 index 0000000000..bb665c259d --- /dev/null +++ b/jsf/src/main/java/com/baeldung/springintegration/resources/messages.properties @@ -0,0 +1,23 @@ +message.unmatchedPasswords = The passwords you have entered do not match +message.valueRequired = This value is required +message.invalidPassword = Your passwords must match and must contain at least one each of upper case letters, lower case letters, and digits. +message.invalidDate = The date value supplied is invalid. It should be of the format MM/DD/YYYY +message.invalidZip = Your zip code should be a 5 digit numeric value +message.conversionError = An invalid value was supplied +label.firstName = First Name +label.lastName = Last Name +label.username = Username +label.firstPassword = Password +label.confirmPassword = Confirm Password +label.saveButton = Save +label.cancelButton = Cancel +label.returnHomeButton = Return +label.dateOfBirth = Date of Birth +label.city = City +label.street = Street Address +label.zip = Zip Code +label.postal = Postal Code +message.success = Operation Successful +message.failure = Operation Failed +account.success = Account Successfully created +conversion.error = An invalid value was submitted for this field diff --git a/jsf/src/main/webapp/META-INF/context.xml b/jsf/src/main/webapp/META-INF/context.xml new file mode 100644 index 0000000000..cf746bfae4 --- /dev/null +++ b/jsf/src/main/webapp/META-INF/context.xml @@ -0,0 +1,2 @@ + + diff --git a/jsf/src/main/webapp/WEB-INF/applicationContext.xml b/jsf/src/main/webapp/WEB-INF/applicationContext.xml new file mode 100644 index 0000000000..8553300e1e --- /dev/null +++ b/jsf/src/main/webapp/WEB-INF/applicationContext.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/jsf/src/main/webapp/WEB-INF/async_config.xml b/jsf/src/main/webapp/WEB-INF/async_config.xml new file mode 100644 index 0000000000..600a279086 --- /dev/null +++ b/jsf/src/main/webapp/WEB-INF/async_config.xml @@ -0,0 +1,11 @@ + + + + true + + + \ No newline at end of file diff --git a/jsf/src/main/webapp/WEB-INF/beans.xml b/jsf/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..4ca8195bea --- /dev/null +++ b/jsf/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,5 @@ + + + diff --git a/jsf/src/main/webapp/WEB-INF/faces-config.xml b/jsf/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000000..6142d81daf --- /dev/null +++ b/jsf/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,50 @@ + + + + + + + + + + com.baeldung.resources.messages + + + msg + + + + + com.baeldung.resources.constraints + + + constraints + + + org.springframework.web.jsf.el.SpringBeanFacesELResolver + + + + /* + + home + /index.xhtml + + + + + + /register.xhtml + + review registration + /review_registration.xhtml + + + + + + + diff --git a/jsf/src/main/webapp/WEB-INF/glassfish-web.xml b/jsf/src/main/webapp/WEB-INF/glassfish-web.xml new file mode 100644 index 0000000000..13e0059fff --- /dev/null +++ b/jsf/src/main/webapp/WEB-INF/glassfish-web.xml @@ -0,0 +1,10 @@ + + + + + + + Keep a copy of the generated servlet class' java code. + + + diff --git a/jsf/src/main/webapp/WEB-INF/web.xml b/jsf/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..9345f201ef --- /dev/null +++ b/jsf/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,42 @@ + + + + javax.faces.PROJECT_STAGE + Production + + + javax.faces.STATE_SAVING_MODE + SERVER + + + + primefaces.PUBLIC_CAPTCHA_KEY + + + 6LdG-84SAAAAALQfp6DuJqd1XLnz3ZlHfhunPPjY + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + *.jsf + + + + 30 + + + + /index.jsf + + + + org.springframework.web.context.ContextLoaderListener + + + + diff --git a/jsf/src/main/webapp/index.xhtml b/jsf/src/main/webapp/index.xhtml new file mode 100644 index 0000000000..d71451abcc --- /dev/null +++ b/jsf/src/main/webapp/index.xhtml @@ -0,0 +1,27 @@ + + + + + + Baeldung | Register + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index 6f63269248..d6a1d7c034 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ spring-security-rest-full spring-thymeleaf spring-zuul + jsf