jsf-spring-integration - chaning the logger

This commit is contained in:
Slavisa Baeldung 2016-05-26 12:56:09 +02:00
parent 98fbb50879
commit 5635d4850b
6 changed files with 60 additions and 69 deletions

View File

@ -13,6 +13,8 @@
<version>0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<!-- JSF -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
@ -25,6 +27,7 @@
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
@ -46,6 +49,30 @@
<version>${org.springframework.version}</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
<!-- <scope>runtime</scope> -->
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
</dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
@ -64,6 +91,12 @@
<properties>
<!-- Spring -->
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
<!-- JSF -->
<com.sun.faces.version>2.1.7</com.sun.faces.version>
<!-- logging -->
<org.slf4j.version>1.7.13</org.slf4j.version>
<logback.version>1.1.3</logback.version>
</properties>
</project>

View File

@ -1,31 +1,25 @@
/*
* 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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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 {
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationBean.class);
@ManagedProperty(value = "#{userManagementDAO}")
transient private IUserManagementDAO theUserDao;
private String userName;
private String operationMessage;
private boolean operationStatus;
/**
* Creates a new instance of RegistrationBean
@ -35,35 +29,24 @@ public class RegistrationBean implements Serializable {
public String createNewUser() {
try {
Logger.getAnonymousLogger().info("Creating new user");
LOGGER.info("Creating new user");
FacesContext context = FacesContext.getCurrentInstance();
operationStatus = theUserDao.createUser(userName); //DAO layer is used to register user using gathered data
boolean operationStatus = theUserDao.createUser(userName);
context.isValidationFailed();
if (operationStatus) {
operationMessage = "User " + userName + " created";
}
} catch (Exception ex) {
Logger.getAnonymousLogger().severe("Error registering new user ");
LOGGER.error("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;
}
@ -79,16 +62,10 @@ public class RegistrationBean implements Serializable {
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

@ -1,10 +0,0 @@
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,14 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -1,23 +1,3 @@
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
message.welcome = Baeldung | Register
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

@ -3,22 +3,19 @@
"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>
<title><h:outputText value="#{msg['message.welcome']}"/></title>
</h:head>
<h:body>
<h:form>
<f:ajax>
<f:ajax render="theGrid">
<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:inputText id="firstName" 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:commandButton value="#{msg['label.saveButton']}" action="#{registration.createNewUser}"/>
<h:outputText value="#{registration.operationMessage}"/>
</h:panelGrid>
</f:ajax>