JAVA-29231 Move modules inside existing container modules (#15492)
This commit is contained in:
+36
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.springintegration.config;
|
||||
|
||||
import com.sun.faces.config.FacesInitializer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.WebApplicationInitializer;
|
||||
import org.springframework.web.context.ContextLoaderListener;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
import java.util.Set;
|
||||
|
||||
public class MainWebAppInitializer extends FacesInitializer implements WebApplicationInitializer {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MainWebAppInitializer.class);
|
||||
|
||||
@Override
|
||||
public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException {
|
||||
super.onStartup(classes, servletContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register and configure all Servlet container components necessary to power the web application.
|
||||
*/
|
||||
@Override
|
||||
public void onStartup(final ServletContext sc) throws ServletException {
|
||||
LOGGER.info("MainWebAppInitializer.onStartup()");
|
||||
sc.setInitParameter("javax.faces.FACELETS_SKIP_COMMENTS", "true");
|
||||
|
||||
// Create the 'root' Spring application context
|
||||
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
||||
root.register(SpringCoreConfig.class);
|
||||
sc.addListener(new ContextLoaderListener(root));
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.springintegration.config;
|
||||
|
||||
import com.baeldung.springintegration.dao.UserManagementDAO;
|
||||
import com.baeldung.springintegration.dao.UserManagementDAOImpl;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class SpringCoreConfig {
|
||||
|
||||
@Bean
|
||||
public UserManagementDAO userManagementDAO() {
|
||||
return new UserManagementDAOImpl();
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package com.baeldung.springintegration.controllers;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.el.ELContextEvent;
|
||||
import javax.el.ELContextListener;
|
||||
import javax.el.LambdaExpression;
|
||||
import javax.faces.application.Application;
|
||||
import javax.faces.application.FacesMessage;
|
||||
import javax.el.LambdaExpression;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.ViewScoped;
|
||||
import javax.faces.context.FacesContext;
|
||||
import java.util.Collection;
|
||||
import java.util.Random;
|
||||
|
||||
@ManagedBean(name = "ELBean")
|
||||
@ViewScoped
|
||||
public class ELSampleBean {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String pageDescription = "This page demos JSF EL Basics";
|
||||
public static final String constantField = "THIS_IS_NOT_CHANGING_ANYTIME_SOON";
|
||||
private int pageCounter;
|
||||
private Random randomIntGen = new Random();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
pageCounter = randomIntGen.nextInt();
|
||||
FacesContext.getCurrentInstance()
|
||||
.getApplication()
|
||||
.addELContextListener(new ELContextListener() {
|
||||
@Override
|
||||
public void contextCreated(ELContextEvent evt) {
|
||||
evt.getELContext()
|
||||
.getImportHandler()
|
||||
.importClass("com.baeldung.springintegration.controllers.ELSampleBean");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void save() {
|
||||
|
||||
}
|
||||
|
||||
public static String constantField() {
|
||||
return constantField;
|
||||
}
|
||||
|
||||
public void saveFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public Long multiplyValue(LambdaExpression expr) {
|
||||
Long theResult = (Long) expr.invoke(FacesContext.getCurrentInstance()
|
||||
.getELContext(), pageCounter);
|
||||
return theResult;
|
||||
}
|
||||
|
||||
public void saveByELEvaluation() {
|
||||
firstName = (String) evaluateEL("#{firstName.value}", String.class);
|
||||
FacesContext ctx = FacesContext.getCurrentInstance();
|
||||
FacesMessage theMessage = new FacesMessage("Name component Evaluated: " + firstName);
|
||||
theMessage.setSeverity(FacesMessage.SEVERITY_INFO);
|
||||
ctx.addMessage(null, theMessage);
|
||||
|
||||
}
|
||||
|
||||
private Object evaluateEL(String elExpression, Class<?> clazz) {
|
||||
Object toReturn = null;
|
||||
FacesContext ctx = FacesContext.getCurrentInstance();
|
||||
Application app = ctx.getApplication();
|
||||
toReturn = app.evaluateExpressionGet(ctx, elExpression, clazz);
|
||||
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the firstName
|
||||
*/
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param firstName the firstName to set
|
||||
*/
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lastName
|
||||
*/
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lastName the lastName to set
|
||||
*/
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pageDescription
|
||||
*/
|
||||
public String getPageDescription() {
|
||||
return pageDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pageDescription the pageDescription to set
|
||||
*/
|
||||
public void setPageDescription(String pageDescription) {
|
||||
this.pageDescription = pageDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the pageCounter
|
||||
*/
|
||||
public int getPageCounter() {
|
||||
return pageCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pageCounter the pageCounter to set
|
||||
*/
|
||||
public void setPageCounter(int pageCounter) {
|
||||
this.pageCounter = pageCounter;
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package com.baeldung.springintegration.controllers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.el.ELContextEvent;
|
||||
import javax.el.ELContextListener;
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.ViewScoped;
|
||||
|
||||
@ManagedBean(name = "helloPFBean")
|
||||
@ViewScoped
|
||||
public class HelloPFBean {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
private String componentSuite;
|
||||
|
||||
private List<Technology> technologies;
|
||||
|
||||
private String inputText;
|
||||
private String outputText;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
firstName = "Hello";
|
||||
lastName = "Primefaces";
|
||||
|
||||
technologies = new ArrayList<Technology>();
|
||||
|
||||
Technology technology1 = new Technology();
|
||||
technology1.setCurrentVersion("10");
|
||||
technology1.setName("Java");
|
||||
|
||||
technologies.add(technology1);
|
||||
|
||||
Technology technology2 = new Technology();
|
||||
technology2.setCurrentVersion("5.0");
|
||||
technology2.setName("Spring");
|
||||
|
||||
technologies.add(technology2);
|
||||
}
|
||||
|
||||
public void onBlurEvent() {
|
||||
outputText = inputText.toUpperCase();
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getComponentSuite() {
|
||||
return componentSuite;
|
||||
}
|
||||
|
||||
public void setComponentSuite(String componentSuite) {
|
||||
this.componentSuite = componentSuite;
|
||||
}
|
||||
|
||||
public List<Technology> getTechnologies() {
|
||||
return technologies;
|
||||
}
|
||||
|
||||
public void setTechnologies(List<Technology> technologies) {
|
||||
this.technologies = technologies;
|
||||
}
|
||||
|
||||
public String getInputText() {
|
||||
return inputText;
|
||||
}
|
||||
|
||||
public void setInputText(String inputText) {
|
||||
this.inputText = inputText;
|
||||
}
|
||||
|
||||
public String getOutputText() {
|
||||
return outputText;
|
||||
}
|
||||
|
||||
public void setOutputText(String outputText) {
|
||||
this.outputText = outputText;
|
||||
}
|
||||
|
||||
public class Technology {
|
||||
private String name;
|
||||
private String currentVersion;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCurrentVersion() {
|
||||
return currentVersion;
|
||||
}
|
||||
|
||||
public void setCurrentVersion(String currentVersion) {
|
||||
this.currentVersion = currentVersion;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.springintegration.controllers;
|
||||
|
||||
import javax.faces.bean.ManagedBean;
|
||||
import javax.faces.bean.SessionScoped;
|
||||
|
||||
@ManagedBean(name = "helloPFMBean")
|
||||
@SessionScoped
|
||||
public class HelloPFMBean {
|
||||
|
||||
private String magicWord;
|
||||
|
||||
public String getMagicWord() {
|
||||
return magicWord;
|
||||
}
|
||||
|
||||
public void setMagicWord(String magicWord) {
|
||||
this.magicWord = magicWord;
|
||||
}
|
||||
|
||||
public String go() {
|
||||
if (this.magicWord != null && this.magicWord.toUpperCase()
|
||||
.equals("BAELDUNG")) {
|
||||
return "pm:success";
|
||||
}
|
||||
return "pm:failure";
|
||||
}
|
||||
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package com.baeldung.springintegration.controllers;
|
||||
|
||||
import com.baeldung.springintegration.dao.UserManagementDAO;
|
||||
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;
|
||||
|
||||
@ManagedBean(name = "registration")
|
||||
@ViewScoped
|
||||
public class RegistrationBean implements Serializable {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationBean.class);
|
||||
|
||||
@ManagedProperty(value = "#{userManagementDAO}")
|
||||
transient private UserManagementDAO userDao;
|
||||
private String userName;
|
||||
private String operationMessage;
|
||||
|
||||
public void createNewUser() {
|
||||
try {
|
||||
LOGGER.info("Creating new user");
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
boolean operationStatus = userDao.createUser(userName);
|
||||
context.isValidationFailed();
|
||||
if (operationStatus) {
|
||||
operationMessage = "User " + userName + " created";
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("Error registering new user ");
|
||||
ex.printStackTrace();
|
||||
operationMessage = "Error " + userName + " not created";
|
||||
}
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public void setUserDao(UserManagementDAO userDao) {
|
||||
this.userDao = userDao;
|
||||
}
|
||||
|
||||
public UserManagementDAO getUserDao() {
|
||||
return this.userDao;
|
||||
}
|
||||
|
||||
public String getOperationMessage() {
|
||||
return operationMessage;
|
||||
}
|
||||
|
||||
public void setOperationMessage(String operationMessage) {
|
||||
this.operationMessage = operationMessage;
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.baeldung.springintegration.dao;
|
||||
|
||||
public interface UserManagementDAO {
|
||||
|
||||
boolean createUser(String newUserData);
|
||||
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.springintegration.dao;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
@Repository
|
||||
public class UserManagementDAOImpl implements UserManagementDAO {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UserManagementDAOImpl.class);
|
||||
|
||||
private List<String> users;
|
||||
|
||||
@PostConstruct
|
||||
public void initUserList() {
|
||||
users = new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createUser(String newUserData) {
|
||||
if (newUserData != null) {
|
||||
users.add(newUserData);
|
||||
LOGGER.info("User {} successfully created", newUserData);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public UserManagementDAOImpl() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user