Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmusgrove committed Jul 7, 2015
0 parents commit d62deb3
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.class

# Package Files #
*.jar
*.war
*.ear

/mydb
/target
/.settings
*.classpath
.project
/target/
/target/
69 changes: 69 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?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">
<modelVersion>4.0.0</modelVersion>

<groupId>com.levelup</groupId>
<artifactId>037-integrate-jsf-spring-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>037-integrate-jsf-spring-boot</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.8</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
67 changes: 67 additions & 0 deletions src/main/java/com/levelup/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.levelup;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.embedded.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
public JSFSpringBean jsfSpringBean() {
return new JSFSpringBean();
}

@Configuration
@Profile("dev")
static class ConfigureJSFContextParameters implements ServletContextInitializer {

@Override
public void onStartup(ServletContext servletContext)
throws ServletException {

servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX",
".xhtml");
servletContext.setInitParameter(
"javax.faces.PARTIAL_STATE_SAVING_METHOD", "true");
servletContext.setInitParameter("javax.faces.PROJECT_STAGE",
"Development");
servletContext.setInitParameter("facelets.DEVELOPMENT", "true");
servletContext.setInitParameter(
"javax.faces.FACELETS_REFRESH_PERIOD", "1");

}
}

@Configuration
@Profile("production")
static class ConfigureJSFContextParametersProd implements ServletContextInitializer {

@Override
public void onStartup(ServletContext servletContext)
throws ServletException {

servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX",
".xhtml");
servletContext.setInitParameter(
"javax.faces.PARTIAL_STATE_SAVING_METHOD", "true");
servletContext.setInitParameter("javax.faces.PROJECT_STAGE",
"Production");
servletContext.setInitParameter("facelets.DEVELOPMENT", "false");
servletContext.setInitParameter(
"javax.faces.FACELETS_REFRESH_PERIOD", "-1");

}
}

}
43 changes: 43 additions & 0 deletions src/main/java/com/levelup/ConfigureJSF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.levelup;

import java.util.HashSet;
import java.util.Set;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.sun.faces.config.FacesInitializer;

@Configuration
public class ConfigureJSF {

@Bean
public ServletRegistrationBean facesServletRegistration() {

ServletRegistrationBean servletRegistrationBean = new JsfServletRegistrationBean();

return servletRegistrationBean;
}

public class JsfServletRegistrationBean extends ServletRegistrationBean {

public JsfServletRegistrationBean() {
super();
}

@Override
public void onStartup(ServletContext servletContext)
throws ServletException {

FacesInitializer facesInitializer = new FacesInitializer();

Set<Class<?>> clazz = new HashSet<Class<?>>();
clazz.add(ConfigureJSF.class);
facesInitializer.onStartup(clazz, servletContext);
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/levelup/JSFSpringBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.levelup;

public class JSFSpringBean {

private String welcomeMessage = "Populated by spring created bean";

public String getWelcomeMessage() {
return welcomeMessage;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/levelup/JsfBean.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.levelup;

import javax.annotation.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean
@RequestScoped
public class JsfBean {

private String welcomeMessage = "Populated by JSF created bean";

public String getWelcomeMessage() {
return welcomeMessage;
}

}
13 changes: 13 additions & 0 deletions src/main/java/com/levelup/ServletInitializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.levelup;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}

}
15 changes: 15 additions & 0 deletions src/main/resources/META-INF/faces-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">

<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
</application>

<lifecycle>
<phase-listener>org.springframework.web.jsf.DelegatingPhaseListenerMulticaster</phase-listener>
</lifecycle>

</faces-config>
1 change: 1 addition & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.profiles.active=dev
26 changes: 26 additions & 0 deletions src/main/webapp/index.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf"
encoding="UTF-8">

<html>

<h:head>

</h:head>

<!--Main Body -->
<h:body>

<h1>Welcome to JSF spring boot tutorial</h1>

<h3>#{jsfBean.welcomeMessage}</h3>
<h3>#{jsfSpringBean.welcomeMessage}</h3>

</h:body>

</html>
</f:view>
18 changes: 18 additions & 0 deletions src/test/java/com/levelup/ApplicationTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.levelup;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration
public class ApplicationTests {

@Test
public void contextLoads() {
}

}

0 comments on commit d62deb3

Please sign in to comment.