Author: ilya_shaikovsky
Date: 2010-12-08 08:43:58 -0500 (Wed, 08 Dec 2010)
New Revision: 20460
Added:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/FileUploadBean.java
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/UplocadedImage.java
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/imgUpload.xhtml
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/samples/
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/samples/imgUpload-sample.xhtml
Modified:
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
trunk/examples/richfaces-showcase/src/main/webapp-gae/WEB-INF/web.xml
trunk/examples/richfaces-showcase/src/main/webapp/WEB-INF/web.xml
Log:
https://jira.jboss.org/browse/RF-9502
Added:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/FileUploadBean.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/FileUploadBean.java
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/FileUploadBean.java 2010-12-08
13:43:58 UTC (rev 20460)
@@ -0,0 +1,91 @@
+package org.richfaces.demo.fileupload;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+
+import javax.faces.bean.ManagedBean;
+import javax.faces.bean.SessionScoped;
+
+import org.richfaces.event.UploadEvent;
+import org.richfaces.model.UploadItem;
+
+/**
+ * @author Ilya Shaikovsky
+ *
+ */
+@ManagedBean
+@SessionScoped
+public class FileUploadBean implements Serializable {
+
+ private ArrayList<UplocadedImage> files = new
ArrayList<UplocadedImage>();
+ private int uploadsAvailable = 5;
+ private boolean autoUpload = false;
+ private boolean useFlash = false;
+
+ public int getSize() {
+ if (getFiles().size() > 0) {
+ return getFiles().size();
+ } else {
+ return 0;
+ }
+ }
+
+ public void paint(OutputStream stream, Object object) throws IOException {
+ stream.write(getFiles().get((Integer) object).getData());
+ }
+
+ public void listener(UploadEvent event) throws Exception {
+ UploadItem item = event.getUploadItem();
+ UplocadedImage file = new UplocadedImage();
+ file.setLength(item.getData().length);
+ file.setName(item.getFileName());
+ file.setData(item.getData());
+ files.add(file);
+ uploadsAvailable--;
+ }
+
+ public String clearUploadData() {
+ files.clear();
+ setUploadsAvailable(5);
+ return null;
+ }
+
+ public long getTimeStamp() {
+ return System.currentTimeMillis();
+ }
+
+ public ArrayList<UplocadedImage> getFiles() {
+ return files;
+ }
+
+ public void setFiles(ArrayList<UplocadedImage> files) {
+ this.files = files;
+ }
+
+ public int getUploadsAvailable() {
+ return uploadsAvailable;
+ }
+
+ public void setUploadsAvailable(int uploadsAvailable) {
+ this.uploadsAvailable = uploadsAvailable;
+ }
+
+ public boolean isAutoUpload() {
+ return autoUpload;
+ }
+
+ public void setAutoUpload(boolean autoUpload) {
+ this.autoUpload = autoUpload;
+ }
+
+ public boolean isUseFlash() {
+ return useFlash;
+ }
+
+ public void setUseFlash(boolean useFlash) {
+ this.useFlash = useFlash;
+ }
+
+}
Added:
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/UplocadedImage.java
===================================================================
---
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/UplocadedImage.java
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/java/org/richfaces/demo/fileupload/UplocadedImage.java 2010-12-08
13:43:58 UTC (rev 20460)
@@ -0,0 +1,52 @@
+package org.richfaces.demo.fileupload;
+
+public class UplocadedImage {
+
+ private String name;
+ private String mime;
+ private long length;
+ private byte[] data;
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public void setData(byte[] data) {
+ this.data = data;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ name = name;
+ int extDot = name.lastIndexOf('.');
+ if (extDot > 0) {
+ String extension = name.substring(extDot + 1);
+ if ("bmp".equals(extension)) {
+ mime = "image/bmp";
+ } else if ("jpg".equals(extension)) {
+ mime = "image/jpeg";
+ } else if ("gif".equals(extension)) {
+ mime = "image/gif";
+ } else if ("png".equals(extension)) {
+ mime = "image/png";
+ } else {
+ mime = "image/unknown";
+ }
+ }
+ }
+
+ public long getLength() {
+ return length;
+ }
+
+ public void setLength(long length) {
+ this.length = length;
+ }
+
+ public String getMime() {
+ return mime;
+ }
+}
Modified:
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml
===================================================================
---
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2010-12-08
13:24:39 UTC (rev 20459)
+++
trunk/examples/richfaces-showcase/src/main/resources/org/richfaces/demo/data/common/navigation.xml 2010-12-08
13:43:58 UTC (rev 20460)
@@ -536,6 +536,16 @@
</sample>
</samples>
</demo>
+ <demo new="true">
+ <id>fileUpload</id>
+ <name>rich:fileUpload</name>
+ <samples>
+ <sample>
+ <id>imgUpload</id>
+ <name>Upload images</name>
+ </sample>
+ </samples>
+ </demo>
</demos>
</group>
<group>
Modified: trunk/examples/richfaces-showcase/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/examples/richfaces-showcase/src/main/webapp/WEB-INF/web.xml 2010-12-08 13:24:39
UTC (rev 20459)
+++ trunk/examples/richfaces-showcase/src/main/webapp/WEB-INF/web.xml 2010-12-08 13:43:58
UTC (rev 20460)
@@ -1,58 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="richfaces-showcase" version="2.5"
-
xmlns="http://java.sun.com/xml/ns/javaee"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <display-name>richfaces-showcase</display-name>
- <context-param>
- <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
- <param-value>/WEB-INF/app-tags.taglib.xml</param-value>
- </context-param>
- <context-param>
- <param-name>org.richfaces.enableControlSkinning</param-name>
- <param-value>true</param-value>
- </context-param>
- <context-param>
- <param-name>org.richfaces.enableControlSkinningClasses</param-name>
- <param-value>false</param-value>
- </context-param>
- <context-param>
- <param-name>org.richfaces.skin</param-name>
- <param-value>#{skinBean.skin}</param-value>
- </context-param>
- <context-param>
- <param-name>javax.faces.PROJECT_STAGE</param-name>
- <param-value>Development</param-value>
- </context-param>
- <context-param>
- <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
- <param-value>server</param-value>
- </context-param>
- <servlet>
- <servlet-name>Faces Servlet</servlet-name>
- <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>Faces Servlet</servlet-name>
- <url-pattern>*.jsf</url-pattern>
- </servlet-mapping>
- <servlet-mapping>
- <servlet-name>Faces Servlet</servlet-name>
- <url-pattern>/faces/*</url-pattern>
- </servlet-mapping>
- <mime-mapping>
- <extension>ecss</extension>
- <mime-type>text/css</mime-type>
- </mime-mapping>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- <login-config>
- <auth-method>BASIC</auth-method>
- </login-config>
+
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+ <display-name>richfaces-showcase</display-name>
+ <context-param>
+ <param-name>javax.faces.FACELETS_LIBRARIES</param-name>
+ <param-value>/WEB-INF/app-tags.taglib.xml</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.richfaces.skin</param-name>
+ <param-value>#{skinBean.skin}</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.richfaces.fileUpload.maxRequestSize</param-name>
+ <param-value>100000</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.richfaces.fileUpload.createTempFiles</param-name>
+ <param-value>false</param-value>
+ </context-param>
+ <context-param>
+ <param-name>javax.faces.PROJECT_STAGE</param-name>
+ <param-value>Development</param-value>
+ </context-param>
+ <context-param>
+ <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
+ <param-value>server</param-value>
+ </context-param>
+ <servlet>
+ <servlet-name>Faces Servlet</servlet-name>
+ <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>*.jsf</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>Faces Servlet</servlet-name>
+ <url-pattern>/faces/*</url-pattern>
+ </servlet-mapping>
+ <mime-mapping>
+ <extension>ecss</extension>
+ <mime-type>text/css</mime-type>
+ </mime-mapping>
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ <welcome-file>index.htm</welcome-file>
+ <welcome-file>index.jsp</welcome-file>
+ <welcome-file>default.html</welcome-file>
+ <welcome-file>default.htm</welcome-file>
+ <welcome-file>default.jsp</welcome-file>
+ </welcome-file-list>
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ </login-config>
</web-app>
Added:
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/imgUpload.xhtml
===================================================================
---
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/imgUpload.xhtml
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/imgUpload.xhtml 2010-12-08
13:43:58 UTC (rev 20460)
@@ -0,0 +1,38 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets">
+
+<ui:composition>
+ <p><b>rich:fileUpload</b> is a component which provides files
+ upload functionality and extends functionality of standard <b>input</b>
+ with <b>type="file"</b>.</p>
+ <p>The next example shows you File Upload which allows you to
+ upload files to the server. Files number allowed to upload is managed
+ with <b>maxFilesQuantity</b> attribute. Every uploaded file should be
+ managed with <b>fileUploadListener</b> which is called after every
+ single file upload is finished.</p>
+ <fieldset><legend><b>Sample limitations</b></legend>This
+ example allows to download <b>up to 5 files</b>. The file extension is
+ limited to <b>GIF, JPG, BMP, PNG</b> and the maximum size of each file
+ must not exceed 100kB</fieldset>
+ <ui:include src="#{demoNavigator.sampleIncludeURI}" />
+ <ui:include src="/templates/includes/source-view.xhtml">
+ <ui:param name="src" value="#{demoNavigator.sampleIncludeURI}"
/>
+ <ui:param name="sourceType" value="xhtml" />
+ <ui:param name="openLabel" value="View Source" />
+ <ui:param name="hideLabel" value="Hide Source" />
+ </ui:include>
+ <p><b>FileUpload requires two context-parameter's to be set in
+ web.xml:</b></p>
+ <ul>
+ <li><b>createTempFiles</b> boolean attribute which defines whether
the
+ uploaded files are stored in temporary files or available in listener
+ just as byte[] data (false for this example).</li>
+ <li><b>maxRequestSize</b> attribute defines max size in bytes of the
+ uploaded files (<u>1000000 for this example</u>).</li>
+ </ul>
+</ui:composition>
+
+</html>
\ No newline at end of file
Added:
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/samples/imgUpload-sample.xhtml
===================================================================
---
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/samples/imgUpload-sample.xhtml
(rev 0)
+++
trunk/examples/richfaces-showcase/src/main/webapp/richfaces/fileUpload/samples/imgUpload-sample.xhtml 2010-12-08
13:43:58 UTC (rev 20460)
@@ -0,0 +1,63 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html
xmlns="http://www.w3.org/1999/xhtml"
+
xmlns:h="http://java.sun.com/jsf/html"
+
xmlns:f="http://java.sun.com/jsf/core"
+
xmlns:ui="http://java.sun.com/jsf/facelets"
+
xmlns:a4j="http://richfaces.org/a4j"
+
xmlns:rich="http://richfaces.org/rich">
+
+<ui:composition>
+
+ <style>
+.top {
+ vertical-align: top;
+}
+
+.info {
+ height: 202px;
+ overflow: auto;
+}
+</style>
+ <h:form>
+ <h:panelGrid columns="2" columnClasses="top,top">
+ <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
+ maxFilesQuantity="#{fileUploadBean.uploadsAvailable}"
id="upload"
+ acceptedTypes="jpg, gif, png, bmp">
+ <a4j:ajax event="uploadcomplete" execute="@none"
render="info" />
+ </rich:fileUpload>
+ <h:panelGroup id="info">
+ <rich:panel bodyClass="info">
+ <f:facet name="header">
+ <h:outputText value="Uploaded Files Info" />
+ </f:facet>
+ <h:outputText value="No files currently uploaded"
+ rendered="#{fileUploadBean.size==0}" />
+ <rich:dataGrid columns="1" value="#{fileUploadBean.files}"
+ var="file" rowKeyVar="row">
+ <rich:panel bodyClass="rich-laguna-panel-no-header">
+ <h:panelGrid columns="2">
+ <a4j:mediaOutput element="img" mimeType="#{file.mime}"
+ createContent="#{fileUploadBean.paint}" value="#{row}"
+ style="width:100px; height:100px;" cacheable="false">
+ <f:param value="#{fileUploadBean.timeStamp}" name="time"
/>
+ </a4j:mediaOutput>
+ <h:panelGrid columns="2">
+ <h:outputText value="File Name:" />
+ <h:outputText value="#{file.name}" />
+ <h:outputText value="File Length(bytes):" />
+ <h:outputText value="#{file.length}" />
+ </h:panelGrid>
+ </h:panelGrid>
+ </rich:panel>
+ </rich:dataGrid>
+ </rich:panel>
+ <br />
+ <a4j:commandButton action="#{fileUploadBean.clearUploadData}"
+ render="info, upload" value="Clear Uploaded Data"
+ rendered="#{fileUploadBean.size>0}" />
+ </h:panelGroup>
+ </h:panelGrid>
+ </h:form>
+</ui:composition>
+
+</html>
\ No newline at end of file
Modified: trunk/examples/richfaces-showcase/src/main/webapp-gae/WEB-INF/web.xml
===================================================================
--- trunk/examples/richfaces-showcase/src/main/webapp-gae/WEB-INF/web.xml 2010-12-08
13:24:39 UTC (rev 20459)
+++ trunk/examples/richfaces-showcase/src/main/webapp-gae/WEB-INF/web.xml 2010-12-08
13:43:58 UTC (rev 20460)
@@ -24,6 +24,14 @@
<param-name>org.richfaces.enableControlSkinningClasses</param-name>
<param-value>false</param-value>
</context-param>
+ <context-param>
+ <param-name>org.richfaces.fileUpload.maxRequestSize</param-name>
+ <param-value>100000</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.richfaces.fileUpload.createTempFiles</param-name>
+ <param-value>false</param-value>
+ </context-param>
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>#{skinBean.skin}</param-value>