This SAP (Single Page Application) illustrates JSF usage inside JAR packaged Spring Boot Application.
JoinFaces autoconfigures PrimeFaces, BootsFaces, ButterFaces, OmniFaces, AngularFaces, Mojarra and MyFaces libraries to run at embedded Tomcat, Jetty or Undertow.
1- Access starter.jsf page at https://joinfaces-example.herokuapp.com/index.jsf. This page can help you to choose the JSF Spring Boot Starter that fits your needs. You may login with credentials
User | Password | Roles |
---|---|---|
persapiens | 123 | ROLE_ADMIN |
nyilmaz | qwe | ROLE_USER |
1- Clone this project
git clone https://github.com/joinfaces/joinfaces-example.git
2- Build
mvn clean install
3- Run
java -jar target/joinfaces-example-2.4.0-SNAPSHOT.jar
4- Access starter page at http://localhost:8080/index.jsf
Includes joinfaces starter dependency. All other jsf dependencies are included transitively.
<parent>
<groupId>org.joinfaces</groupId>
<artifactId>jsf-spring-boot-parent</artifactId>
<version>2.4.0</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>org.joinfaces</groupId>
<artifactId>jsf-spring-boot-starter</artifactId>
</dependency>
</dependencies>
If you prefer Jetty instead of Tomcat, change artifactId jsf-spring-boot-starter to jsf-jetty-spring-boot-starter in order to use Jetty servlet container.
If you prefer Undertow instead of Tomcat, change artifactId jsf-spring-boot-starter to jsf-undertow-spring-boot-starter in order to use Undertow servlet container.
If you prefer MyFaces instead of Mojarra, change artifactId jsf-spring-boot-starter to jsf-myfaces-spring-boot-starter in order to use MyFaces JSF Implementation.
If you prefer Jetty instead of Tomcat and MyFaces instead of Mojarra, change artifactId jsf-spring-boot-starter to jsf-jetty-mojarra-spring-boot-starter.
If you prefer Undertow instead of Tomcat and MyFaces instead of Mojarra, change artifactId jsf-spring-boot-starter to jsf-undertow-mojarra-spring-boot-starter.
Note that spring-boot-starter-security is included to secure the application.
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
Configure jsf.PROJECT_STATE and jsf.primefaces.THEME properties.
jsf:
PROJECT_STAGE: Development
primefaces:
theme: overcast
Example page to help you choose the right JSF Spring Boot Starter for you.
Note that xhtml, js, css and images files should be located at src/main/resources/META-INF/resources directory to JSF use them.
Look at authorize and anonymous jsf spring security facelet tags in action to secure page information.
<sec:authorize access="hasRole('ROLE_ADMIN')">
<p:panelGrid columns="1" rendered="#{sec:isFullyAuthenticated()}">
<p:link title="Logout" href="/logout">
<p:outputLabel value="You are logged in as an ADMIN" />
</p:link>
</p:panelGrid>
</sec:authorize>
Very simple spring main application. Only SpringBootApplication annotation is required.
@SpringBootApplication public class JoinFacesExampleApplication {
Spring Security configuration class to secure authentication with credentials to persapiens and nyilmaz users.
Managed bean using ViewScoped CDI annotation. The equivalent spring scope of ViewScoped annotation is configured automatically by Jsf Spring Boot Starter.
@Named @ViewScoped public class StarterMBean {
- Take a look at JoinFaces Wiki.
- Report questions and bugs at github.com/joinfaces/joinfaces-example/issues.
- Report documentation, features, enhancement and bugs at github.com/joinfaces/joinfaces-example/issues.
- Pull requests are welcome.