Skip to content

Commit e904dee

Browse files
committed
Fixes issue #13 - Add @InitParameterMap example
1 parent d4d1566 commit e904dee

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

jsf/LICENSE renamed to LICENSE

File renamed without changes.

jsf/initParameterMap/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Jakarta EE - JSF - An injected InitParameterMap example
2+
3+
This example demonstrates how to use the @InitParameterMap annotation into a bean.

jsf/initParameterMap/pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
7+
<parent>
8+
<artifactId>project</artifactId>
9+
<groupId>jakartaee.examples.jsf</groupId>
10+
<version>8-SNAPSHOT</version>
11+
</parent>
12+
<artifactId>initParameterMap</artifactId>
13+
<packaging>war</packaging>
14+
<name>Jakarta EE - JSF - An injected InitParameterMap example</name>
15+
<dependencies>
16+
<dependency>
17+
<groupId>javax</groupId>
18+
<artifactId>javaee-web-api</artifactId>
19+
<scope>provided</scope>
20+
</dependency>
21+
</dependencies>
22+
<properties>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
</properties>
25+
</project>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Permission to use, copy, modify, and/or distribute this software for any
3+
* purpose with or without fee is hereby granted.
4+
*
5+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIMS ALL WARRANTIES
6+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
7+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR
8+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
9+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
10+
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
11+
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
12+
*/
13+
package jakartaee.examples.jsf.initParameterMap;
14+
15+
import java.io.Serializable;
16+
import java.util.Map;
17+
import javax.enterprise.context.RequestScoped;
18+
import javax.faces.annotation.FacesConfig;
19+
import javax.faces.annotation.InitParameterMap;
20+
import javax.inject.Inject;
21+
import javax.inject.Named;
22+
23+
/**
24+
* A request scoped bean injecting the init parameter map.
25+
*
26+
* @author Manfred Riem ([email protected])
27+
*/
28+
@Named(value = "initParameterMapBean")
29+
@RequestScoped
30+
@FacesConfig(version = FacesConfig.Version.JSF_2_3)
31+
public class InitParameterMapBean implements Serializable {
32+
33+
/**
34+
* Stores the request cookie map.
35+
*/
36+
@Inject
37+
@InitParameterMap
38+
private Map<String, String> initParameterMap;
39+
40+
/**
41+
* Get the init parameter map.
42+
*
43+
* @return the init parametere map.
44+
*/
45+
public Map<String, String> getInitParameterMap() {
46+
return initParameterMap;
47+
}
48+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<web-app version="3.0"
4+
xmlns="http://java.sun.com/xml/ns/javaee"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
7+
<servlet>
8+
<servlet-name>Faces Servlet</servlet-name>
9+
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
10+
<load-on-startup>1</load-on-startup>
11+
</servlet>
12+
<servlet-mapping>
13+
<servlet-name>Faces Servlet</servlet-name>
14+
<url-pattern>*.xhtml</url-pattern>
15+
</servlet-mapping>
16+
<welcome-file-list>
17+
<welcome-file>index.xhtml</welcome-file>
18+
</welcome-file-list>
19+
</web-app>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version='1.0' encoding='UTF-8' ?>
2+
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4+
5+
<html xmlns="http://www.w3.org/1999/xhtml"
6+
xmlns:h="http://xmlns.jcp.org/jsf/html">
7+
<h:head>
8+
<title>An injected InitParameterMap example</title>
9+
</h:head>
10+
<h:body>
11+
<p>
12+
This example illustrates you can use @InitParameterMap to get access
13+
to the init parameters using a map in your beans. You will see the
14+
contents of the map below.
15+
</p>
16+
<p style="max-width: 800px; word-wrap: break-word;">
17+
<h:outputText value="#{initParameterMapBean.initParameterMap}"/>
18+
</p>
19+
</h:body>
20+
</html>

0 commit comments

Comments
 (0)