Skip to content

Commit 193adf8

Browse files
jsf-spring-integration - minor refactors
1 parent c76666a commit 193adf8

3 files changed

Lines changed: 27 additions & 38 deletions

File tree

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,30 @@
1010
import javax.faces.context.FacesContext;
1111
import java.io.Serializable;
1212

13-
1413
@ManagedBean(name = "registration")
1514
@ViewScoped
1615
public class RegistrationBean implements Serializable {
1716
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationBean.class);
1817

1918
@ManagedProperty(value = "#{userManagementDAO}")
20-
transient private IUserManagementDAO theUserDao;
19+
transient private IUserManagementDAO userDao;
2120
private String userName;
2221
private String operationMessage;
2322

24-
/**
25-
* Creates a new instance of RegistrationBean
26-
*/
27-
public RegistrationBean() {
28-
}
29-
30-
public String createNewUser() {
23+
public void createNewUser() {
3124
try {
3225
LOGGER.info("Creating new user");
3326
FacesContext context = FacesContext.getCurrentInstance();
34-
boolean operationStatus = theUserDao.createUser(userName);
27+
boolean operationStatus = userDao.createUser(userName);
3528
context.isValidationFailed();
3629
if (operationStatus) {
3730
operationMessage = "User " + userName + " created";
3831
}
3932
} catch (Exception ex) {
4033
LOGGER.error("Error registering new user ");
4134
ex.printStackTrace();
35+
operationMessage = "Error " + userName + " not created";
4236
}
43-
return null;
4437
}
4538

4639
public String getUserName() {
@@ -51,15 +44,12 @@ public void setUserName(String userName) {
5144
this.userName = userName;
5245
}
5346

54-
/**
55-
* @param theUserDao the theUserDao to set
56-
*/
57-
public void setTheUserDao(IUserManagementDAO theUserDao) {
58-
this.theUserDao = theUserDao;
47+
public void setUserDao(IUserManagementDAO userDao) {
48+
this.userDao = userDao;
5949
}
6050

61-
public IUserManagementDAO getTheUserDao() {
62-
return this.theUserDao;
51+
public IUserManagementDAO getUserDao() {
52+
return this.userDao;
6353
}
6454

6555
public String getOperationMessage() {

‎jsf/src/main/webapp/WEB-INF/web.xml‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,8 @@
99
<param-value>SERVER</param-value>
1010
</context-param>
1111
<context-param>
12-
<param-name>
13-
primefaces.PUBLIC_CAPTCHA_KEY
14-
</param-name>
15-
<param-value>
16-
6LdG-84SAAAAALQfp6DuJqd1XLnz3ZlHfhunPPjY
17-
</param-value>
12+
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
13+
<param-value>true</param-value>
1814
</context-param>
1915
<servlet>
2016
<servlet-name>Faces Servlet</servlet-name>

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@
22
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
33
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
44
<html xmlns="http://www.w3.org/1999/xhtml"
5-
xmlns:h="http://java.sun.com/jsf/html"
6-
xmlns:f="http://java.sun.com/jsf/core">
5+
xmlns:h="http://java.sun.com/jsf/html">
76
<h:head>
87
<title><h:outputText value="#{msg['message.welcome']}"/></title>
98
</h:head>
109
<h:body>
11-
<h:form>
12-
<f:ajax render="theGrid">
13-
<h:panelGrid id="theGrid" columns="3">
14-
<h:outputText value="Username"/>
15-
<h:inputText id="firstName" required="true" requiredMessage="#{msg['message.valueRequired']}"
16-
value="#{registration.userName}"/>
17-
<h:message for="firstName"/>
18-
<h:commandButton value="#{msg['label.saveButton']}" action="#{registration.createNewUser}"/>
19-
<h:outputText value="#{registration.operationMessage}"/>
20-
</h:panelGrid>
21-
</f:ajax>
22-
</h:form>
10+
<h:form>
11+
<h:panelGrid id="theGrid" columns="3">
12+
<h:outputText value="Username"/>
13+
<h:inputText id="firstName" binding="#{userName}" required="true" requiredMessage="#{msg['message.valueRequired']}"
14+
value="#{registration.userName}"/>
15+
<h:message for="firstName" style="color:red;"/>
16+
<h:commandButton value="#{msg['label.saveButton']}" action="#{registration.createNewUser}"
17+
process="@this"/>
18+
<!--
19+
Accessing the Spring bean directly from the page
20+
<h:commandButton value="Save"
21+
action="#{registration.userDao.createUser(userName.value)}"/>
22+
-->
23+
<h:outputText value="#{registration.operationMessage}" style="color:green;"/>
24+
</h:panelGrid>
25+
</h:form>
2326
</h:body>
2427
</html>
2528

0 commit comments

Comments
 (0)