spring-jsf-integration - mavenizing

This commit is contained in:
Slavisa Avramovic 2016-05-21 11:28:31 +02:00 committed by Slavisa Baeldung
parent f972513e2b
commit ef53002000
16 changed files with 402 additions and 0 deletions

37
jsf/pom.xml Normal file
View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jsf</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- http://mvnrepository.com/artifact/com.sun.faces/mojarra-jsf-impl -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>mojarra-jsf-impl</artifactId>
<version>2.0.0-b04</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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<String> users;
@PostConstruct
public void initUserList() {
users = new ArrayList<String>();
}
@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() {
}
}

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Baeldung"/>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context/spring-context-2.5.xsd"
xmlns:lang="http://www.springframework.org/schema/lang/spring-lang-2.5.xsd"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/context/spring-context-2.5.xsd/spring-spring-context-2.5.xsd-3.1.1.RELEASE.xsd
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/jee/spring-jee-2.5.xsd/spring-spring-jee-2.5.xsd-3.1.1.RELEASE.xsd
http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/lang/spring-lang-2.5.xsd/spring-spring-lang-2.5.xsd-3.1.1.RELEASE.xsd
">
<bean class="org.springframework.context.annotation.CommonAnnotationBeanPostProcessor" />
<bean class="com.baeldung.dao.UserManagementDAOImpl" id="userManagementDAO"/>
</beans>

View File

@ -0,0 +1,11 @@
<bindings
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="http://localhost:8084/AxiaTest/TestIt?wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
<bindings node="wsdl:definitions">
<package name="com.me.transport.test"/>
<enableAsyncMapping>true</enableAsyncMapping>
</bindings>
</bindings>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans 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/beans_1_0.xsd">
</beans>

View File

@ -0,0 +1,50 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config version="2.1"
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_1.xsd">
<application>
<resource-bundle>
<base-name>
com.baeldung.resources.messages
</base-name>
<var>
msg
</var>
</resource-bundle>
<resource-bundle>
<base-name>
com.baeldung.resources.constraints
</base-name>
<var>
constraints
</var>
</resource-bundle>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>
<navigation-rule>
<from-view-id>/*</from-view-id>
<navigation-case>
<from-outcome>home</from-outcome>
<to-view-id>/index.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<navigation-rule>
<from-view-id>/register.xhtml</from-view-id>
<navigation-case>
<from-outcome>review registration</from-outcome>
<to-view-id>/review_registration.xhtml</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
</faces-config>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<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>
</glassfish-web-app>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_MODE</param-name>
<param-value>SERVER</param-value>
</context-param>
<context-param>
<param-name>
primefaces.PUBLIC_CAPTCHA_KEY
</param-name>
<param-value>
6LdG-84SAAAAALQfp6DuJqd1XLnz3ZlHfhunPPjY
</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/index.jsf</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>

View File

@ -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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Baeldung | Register</title>
</h:head>
<h:body>
<h:form>
<f:ajax>
<h:panelGrid id="theGrid" columns="3">
<h:outputText value="Username"/>
<h:inputText id="firstName" binding="#{userNameTextbox}" required="true" requiredMessage="#{msg['message.valueRequired']}" value="#{registration.userName}"/>
<h:message for="firstName" />
<h:commandButton value="#{msg['label.saveButton']}" action="#{registration.theUserDao.createUser(userNameTextbox.value)}"/>
<h:outputText value="#{registration.operationMessage}"/>
</h:panelGrid>
</f:ajax>
</h:form>
</h:body>
</html>

View File

@ -64,6 +64,7 @@
<module>spring-security-rest-full</module>
<module>spring-thymeleaf</module>
<module>spring-zuul</module>
<module>jsf</module>
</modules>