Skip to content

Commit 5635d48

Browse files
jsf-spring-integration - chaning the logger
1 parent 98fbb50 commit 5635d48

6 files changed

Lines changed: 60 additions & 69 deletions

File tree

‎jsf/pom.xml‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
<version>0.1-SNAPSHOT</version>
1414
<packaging>war</packaging>
1515
<dependencies>
16+
<!-- JSF -->
17+
1618
<dependency>
1719
<groupId>com.sun.faces</groupId>
1820
<artifactId>jsf-api</artifactId>
@@ -25,6 +27,7 @@
2527
</dependency>
2628

2729
<!-- Spring -->
30+
2831
<dependency>
2932
<groupId>org.springframework</groupId>
3033
<artifactId>spring-web</artifactId>
@@ -46,6 +49,30 @@
4649
<version>${org.springframework.version}</version>
4750
</dependency>
4851

52+
<!-- logging -->
53+
54+
<dependency>
55+
<groupId>org.slf4j</groupId>
56+
<artifactId>slf4j-api</artifactId>
57+
<version>${org.slf4j.version}</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>ch.qos.logback</groupId>
61+
<artifactId>logback-classic</artifactId>
62+
<version>${logback.version}</version>
63+
<!-- <scope>runtime</scope> -->
64+
</dependency>
65+
<dependency>
66+
<groupId>org.slf4j</groupId>
67+
<artifactId>jcl-over-slf4j</artifactId>
68+
<version>${org.slf4j.version}</version>
69+
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
70+
</dependency>
71+
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
72+
<groupId>org.slf4j</groupId>
73+
<artifactId>log4j-over-slf4j</artifactId>
74+
<version>${org.slf4j.version}</version>
75+
</dependency>
4976
</dependencies>
5077
<build>
5178
<plugins>
@@ -64,6 +91,12 @@
6491
<properties>
6592
<!-- Spring -->
6693
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
94+
95+
<!-- JSF -->
6796
<com.sun.faces.version>2.1.7</com.sun.faces.version>
97+
98+
<!-- logging -->
99+
<org.slf4j.version>1.7.13</org.slf4j.version>
100+
<logback.version>1.1.3</logback.version>
68101
</properties>
69102
</project>

‎jsf/src/main/java/com/baeldung/springintegration/controllers/RegistrationBean.java‎

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,25 @@
1-
/*
2-
* To change this template, choose Tools | Templates
3-
* and open the template in the editor.
4-
*/
51
package com.baeldung.springintegration.controllers;
62

73
import com.baeldung.springintegration.dao.IUserManagementDAO;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
86

97
import javax.faces.bean.ManagedBean;
108
import javax.faces.bean.ManagedProperty;
119
import javax.faces.bean.ViewScoped;
1210
import javax.faces.context.FacesContext;
1311
import java.io.Serializable;
14-
import java.util.logging.Logger;
1512

16-
/**
17-
*
18-
* @author Tayo
19-
*/
13+
2014
@ManagedBean(name = "registration")
2115
@ViewScoped
2216
public class RegistrationBean implements Serializable {
17+
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationBean.class);
2318

2419
@ManagedProperty(value = "#{userManagementDAO}")
2520
transient private IUserManagementDAO theUserDao;
2621
private String userName;
2722
private String operationMessage;
28-
private boolean operationStatus;
2923

3024
/**
3125
* Creates a new instance of RegistrationBean
@@ -35,35 +29,24 @@ public RegistrationBean() {
3529

3630
public String createNewUser() {
3731
try {
38-
Logger.getAnonymousLogger().info("Creating new user");
32+
LOGGER.info("Creating new user");
3933
FacesContext context = FacesContext.getCurrentInstance();
40-
operationStatus = theUserDao.createUser(userName); //DAO layer is used to register user using gathered data
34+
boolean operationStatus = theUserDao.createUser(userName);
4135
context.isValidationFailed();
4236
if (operationStatus) {
43-
4437
operationMessage = "User " + userName + " created";
4538
}
4639
} catch (Exception ex) {
47-
Logger.getAnonymousLogger().severe("Error registering new user ");
40+
LOGGER.error("Error registering new user ");
4841
ex.printStackTrace();
4942
}
5043
return null;
5144
}
5245

53-
public String returnHome() {
54-
return "home";
55-
}
56-
57-
/**
58-
* @return the name
59-
*/
6046
public String getUserName() {
6147
return userName;
6248
}
6349

64-
/**
65-
* @param userName the name to set
66-
*/
6750
public void setUserName(String userName) {
6851
this.userName = userName;
6952
}
@@ -79,16 +62,10 @@ public IUserManagementDAO getTheUserDao() {
7962
return this.theUserDao;
8063
}
8164

82-
/**
83-
* @return the operationMessage
84-
*/
8565
public String getOperationMessage() {
8666
return operationMessage;
8767
}
8868

89-
/**
90-
* @param operationMessage the operationMessage to set
91-
*/
9269
public void setOperationMessage(String operationMessage) {
9370
this.operationMessage = operationMessage;
9471
}

‎jsf/src/main/resources/constraints.properties‎

Lines changed: 0 additions & 10 deletions
This file was deleted.

‎jsf/src/main/resources/logback.xml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<configuration>
2+
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>web - %date [%thread] %-5level %logger{36} - %message%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
14+
</configuration>
Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,3 @@
1-
message.unmatchedPasswords = The passwords you have entered do not match
21
message.valueRequired = This value is required
3-
message.invalidPassword = Your passwords must match and must contain at least one each of upper case letters, lower case letters, and digits.
4-
message.invalidDate = The date value supplied is invalid. It should be of the format MM/DD/YYYY
5-
message.invalidZip = Your zip code should be a 5 digit numeric value
6-
message.conversionError = An invalid value was supplied
7-
label.firstName = First Name
8-
label.lastName = Last Name
9-
label.username = Username
10-
label.firstPassword = Password
11-
label.confirmPassword = Confirm Password
2+
message.welcome = Baeldung | Register
123
label.saveButton = Save
13-
label.cancelButton = Cancel
14-
label.returnHomeButton = Return
15-
label.dateOfBirth = Date of Birth
16-
label.city = City
17-
label.street = Street Address
18-
label.zip = Zip Code
19-
label.postal = Postal Code
20-
message.success = Operation Successful
21-
message.failure = Operation Failed
22-
account.success = Account Successfully created
23-
conversion.error = An invalid value was submitted for this field

‎jsf/src/main/webapp/index.xhtml‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@
33
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
44
<html xmlns="http://www.w3.org/1999/xhtml"
55
xmlns:h="http://java.sun.com/jsf/html"
6-
76
xmlns:f="http://java.sun.com/jsf/core">
8-
97
<h:head>
10-
<title>Baeldung | Register</title>
8+
<title><h:outputText value="#{msg['message.welcome']}"/></title>
119
</h:head>
1210
<h:body>
1311
<h:form>
14-
<f:ajax>
12+
<f:ajax render="theGrid">
1513
<h:panelGrid id="theGrid" columns="3">
1614
<h:outputText value="Username"/>
17-
<h:inputText id="firstName" binding="#{userNameTextbox}" required="true"
18-
requiredMessage="#{msg['message.valueRequired']}" value="#{registration.userName}"/>
15+
<h:inputText id="firstName" required="true" requiredMessage="#{msg['message.valueRequired']}"
16+
value="#{registration.userName}"/>
1917
<h:message for="firstName"/>
20-
<h:commandButton value="#{msg['label.saveButton']}"
21-
action="#{registration.theUserDao.createUser(userNameTextbox.value)}"/>
18+
<h:commandButton value="#{msg['label.saveButton']}" action="#{registration.createNewUser}"/>
2219
<h:outputText value="#{registration.operationMessage}"/>
2320
</h:panelGrid>
2421
</f:ajax>

0 commit comments

Comments
 (0)