Skip to content

Commit 8f67b5a

Browse files
committed
Added very simple hello world JSF sample setup in EE 8 style
1 parent ffc9394 commit 8f67b5a

File tree

9 files changed

+156
-2
lines changed

9 files changed

+156
-2
lines changed

jsf/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The [JSR 372](https://jcp.org/en/jsr/detail?id=372) specifies the next version o
44

55
## Samples ##
66

7+
- hello-world shows a typical "hello world" that prints this often used sentence coming from a backing bean
78
- extensionless-mapping shows how to configure JSF so that views can be requested without using an extension
89

910

jsf/extensionless-mapping/pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
</parent>
99

1010
<artifactId>extensionless-mapping</artifactId>
11+
<packaging>war</packaging>
1112
<name>Java EE 8 Samples: JSF - Extensionless Mapping</name>
1213

14+
1315
</project>

jsf/hello-world/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Java EE 8 Samples: JSF 2.3 - Hello world#
2+
3+
The [JSR 372](https://jcp.org/en/jsr/detail?id=372) specifies the next version of JavaServer Faces - JSF 2.3.
4+
5+
A very simple example consisting out of a single page, a backing bean and a bean that activates JSF.
6+
The page prints "Hello world, from JSF!" which comes from the backing bean.
7+
8+
9+

jsf/hello-world/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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>
3+
4+
<parent>
5+
<groupId>org.javaee8</groupId>
6+
<artifactId>jsf</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>hello-world</artifactId>
11+
<packaging>war</packaging>
12+
13+
<name>Java EE 8 Samples: JSF - Hello World</name>
14+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee8.jsf.hello.world;
3+
4+
import javax.enterprise.context.ApplicationScoped;
5+
import javax.faces.annotation.FacesConfig;
6+
7+
/**
8+
* This class is needed to activate JSF and configure it to be the
9+
* right version. Without this being present an explicit mapping
10+
* of the FacesServlet in web.xml would be required, but JSF 2.3
11+
* would then run in a JSF 2.2 compatibility mode.
12+
*
13+
* @author Arjan Tijms
14+
*/
15+
@FacesConfig
16+
@ApplicationScoped
17+
public class ApplicationInit {
18+
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee8.jsf.hello.world;
3+
4+
import javax.enterprise.context.RequestScoped;
5+
import javax.inject.Named;
6+
7+
@Named
8+
@RequestScoped
9+
public class HelloBacking {
10+
11+
public String getHello() {
12+
return "Hello world, from JSF!";
13+
}
14+
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
<!--
3+
Copyright Payara Services Limited
4+
-->
5+
<!DOCTYPE html>
6+
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://xmlns.jcp.org/jsf/html">
7+
8+
<h:head>
9+
<title>Hello</title>
10+
</h:head>
11+
12+
<h:body>
13+
<p>
14+
JSF says:
15+
</p>
16+
<p>
17+
<b>#{helloBacking.hello}</b>
18+
</p>
19+
</h:body>
20+
</html>
21+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/** Copyright Payara Services Limited **/
2+
package org.javaee8.jsf.hello.world;
3+
4+
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
5+
import static org.junit.Assert.assertTrue;
6+
7+
import java.io.File;
8+
import java.io.IOException;
9+
import java.net.URL;
10+
11+
import org.javaee8.jsf.hello.world.ApplicationInit;
12+
import org.jboss.arquillian.container.test.api.Deployment;
13+
import org.jboss.arquillian.container.test.api.RunAsClient;
14+
import org.jboss.arquillian.junit.Arquillian;
15+
import org.jboss.arquillian.test.api.ArquillianResource;
16+
import org.jboss.shrinkwrap.api.spec.WebArchive;
17+
import org.junit.After;
18+
import org.junit.Before;
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
22+
import com.gargoylesoftware.htmlunit.WebClient;
23+
import com.gargoylesoftware.htmlunit.html.HtmlPage;
24+
25+
/**
26+
*
27+
* @author Arjan Tijms
28+
*
29+
*/
30+
@RunWith(Arquillian.class)
31+
public class JSFHelloWorldTest {
32+
33+
@ArquillianResource
34+
private URL base;
35+
36+
private WebClient webClient;
37+
38+
@Before
39+
public void setup() {
40+
webClient = new WebClient();
41+
}
42+
43+
@After
44+
public void teardown() {
45+
webClient.close();
46+
}
47+
48+
@Deployment
49+
public static WebArchive deploy() {
50+
WebArchive war =
51+
create(WebArchive.class)
52+
.addClasses(ApplicationInit.class, HelloBacking.class)
53+
.addAsWebResource(new File("src/main/webapp/hello.xhtml"))
54+
;
55+
56+
System.out.println("War to be deployed contains: \n" + war.toString(true));
57+
58+
return war;
59+
}
60+
61+
62+
@Test
63+
@RunAsClient
64+
public void testHelloWorld() throws IOException {
65+
HtmlPage page = webClient.getPage(base + "hello.xhtml");
66+
67+
assertTrue(page.asXml().contains("Hello world, from JSF!"));
68+
}
69+
70+
71+
72+
}

jsf/pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
<artifactId>samples-parent</artifactId>
77
<version>1.0-SNAPSHOT</version>
88
</parent>
9-
9+
1010
<artifactId>jsf</artifactId>
1111
<packaging>pom</packaging>
1212
<name>Java EE 8 Samples: JSF</name>
1313

1414
<modules>
15-
<module>extensionless-mapping</module>
15+
<module>hello-world</module>
16+
<module>extensionless-mapping</module>
1617
</modules>
1718

1819
<dependencies>

0 commit comments

Comments
 (0)