Skip to content

Commit d7f0a69

Browse files
committed
Fixes issue #14 - Add h:inputFile example
1 parent a27557f commit d7f0a69

File tree

7 files changed

+131
-1
lines changed

7 files changed

+131
-1
lines changed

jsf/inputFile/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Jakarta EE - JSF - An h:inputFile example
2+
3+
This example demonstrates how to use h:inputFile.

jsf/inputFile/pom.xml

+25
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>inputFile</artifactId>
13+
<packaging>war</packaging>
14+
<name>Jakarta EE - JSF - An h:inputFile 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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.samples.jsf.inputFile;
14+
15+
import java.util.Date;
16+
import javax.inject.Named;
17+
import javax.enterprise.context.RequestScoped;
18+
import javax.servlet.http.Part;
19+
20+
/**
21+
* A request scoped bean for using with the h:inputFile example.
22+
*
23+
* @author Manfred Riem ([email protected])
24+
*/
25+
@Named(value = "inputFileBean")
26+
@RequestScoped
27+
public class InputFileBean {
28+
29+
/**
30+
* Stores the part.
31+
*/
32+
private Part part;
33+
34+
/**
35+
* Get the file (part).
36+
*
37+
* @return the time.
38+
*/
39+
public Part getFile() {
40+
return part;
41+
}
42+
43+
/**
44+
* Set the file.
45+
*
46+
* @param part the part.
47+
*/
48+
public void setFile(Part part) {
49+
this.part = part;
50+
}
51+
52+
/**
53+
* Submit.
54+
*
55+
* @return ""
56+
*/
57+
public String submit() {
58+
return "";
59+
}
60+
}
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>
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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>InputFile example</title>
9+
</h:head>
10+
<h:body>
11+
<p>
12+
As this example uses h:inputFile you will need to upload a file
13+
and then click submit to see it in action.
14+
</p>
15+
<h:form enctype="multipart/form-data">
16+
<h:inputFile value="#{inputFileBean.file}"/>
17+
<h:commandButton value="Submit" action="#{inputFileBean.submit}"/>
18+
</h:form>
19+
<br/>
20+
File uploaded: <h:outputText value="#{inputFileBean.file}"/>
21+
</h:body>
22+
</html>

jsf/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<module>externalContext</module>
2020
<module>facesContext</module>
2121
<module>initParameterMap</module>
22+
<module>inputFile</module>
2223
<module>managedProperty</module>
2324
<module>requestCookieMap</module>
2425
<module>requestScoped</module>

jsf/viewScoped/src/main/java/jakartaee/samples/jsf/viewScoped/ViewScopedBean.java renamed to jsf/viewScoped/src/main/java/jakartaee/examples/jsf/viewScoped/ViewScopedBean.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1111
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1212
*/
13-
package jakartaee.samples.jsf.viewScoped;
13+
package jakartaee.examples.jsf.viewScoped;
1414

1515
import java.io.Serializable;
1616
import java.util.Date;

0 commit comments

Comments
 (0)