[richfaces-svn-commits] JBoss Rich Faces SVN: r6301 - in trunk/sandbox/samples/fileUploadDemo/src/main: webapp/pages and 1 other directory.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Feb 22 10:26:08 EST 2008


Author: andrei_exadel
Date: 2008-02-22 10:26:08 -0500 (Fri, 22 Feb 2008)
New Revision: 6301

Added:
   trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/FileData.java
Modified:
   trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/Bean.java
   trunk/sandbox/samples/fileUploadDemo/src/main/webapp/pages/index.jsp
Log:
demo site update

Modified: trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/Bean.java
===================================================================
--- trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/Bean.java	2008-02-22 15:25:37 UTC (rev 6300)
+++ trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/Bean.java	2008-02-22 15:26:08 UTC (rev 6301)
@@ -21,20 +21,14 @@
 
 package org.richfaces;
 
-import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
-import javax.faces.event.ActionEvent;
-import javax.faces.event.FacesEvent;
-
 import org.richfaces.event.UploadEvent;
 
 /**
@@ -47,9 +41,32 @@
 	
 	private boolean flag;
 	
+	private String fileTypes = "*";
+	
+	private Integer maxFiles = 5;
+	
+	private String width = "400";
+	
+	private String height = "210";
+	
 	public boolean isFlag() {
 		return flag;
 	}
+	
+	public List getFileList() {
+	    if (data != null) {
+		List fileList = new ArrayList();
+		for (Object o : data.keySet()) {
+		    String name = (String)o;
+		    File file = (File)data.get(o);
+		    if (file != null) {
+			fileList.add(new FileData(name));
+		    }
+		}
+		return fileList;
+	    }
+	    return null;
+	}
 
 	public void setFlag(boolean flag) {
 		this.flag = flag;
@@ -57,35 +74,10 @@
 	
 	public void listener(UploadEvent event) throws IOException{
 	    File file = event.getFile();
-	    System.out.println("File name : " + file.getAbsolutePath());
+	   System.out.println("File : '" + event.getFileName() + "' was uploaded");
+	   System.out.println("Absolute Path : '" + file.getAbsolutePath() + "'!");
 	}
 
-	public void action(ActionEvent event) {
-	try {
-	    if (data != null) {
-		for (String name : (String [])data.keySet().toArray(new String [0])) {
-		    System.out.println("\nFile Name : " + name);
-		    File file = (File)data.get(name);
-		    
-		    FileInputStream stream = new FileInputStream(file);
-		    ByteArrayOutputStream buffer = new ByteArrayOutputStream(4096);
-		    byte [] bytes = new byte[4096];
-		    int read;
-		    while ((read = stream.read(bytes)) != -1) {
-			buffer.write(bytes, 0 , read);
-		    }
-		    stream.close();
-		    data.remove(name);
-		    file.delete();
-		    System.out.println(buffer.toString());
-   
-		}
-	    }
-	} catch (Exception e) {
-	    e.getMessage();
-	}
-    }
-
 	/**
 	 * @return the data
 	 */
@@ -99,7 +91,64 @@
 	public void setData(Map<String, InputStream> data) {
 	    this.data = data;
 	}
+
+	/**
+	 * @return the fileTypes
+	 */
+	public String getFileTypes() {
+	    return fileTypes;
+	}
+
+	/**
+	 * @param fileTypes the fileTypes to set
+	 */
+	public void setFileTypes(String fileTypes) {
+	    this.fileTypes = fileTypes;
+	}
+
+	/**
+	 * @return the maxFiles
+	 */
+	public Integer getMaxFiles() {
+	    return maxFiles;
+	}
+
+	/**
+	 * @param maxFiles the maxFiles to set
+	 */
+	public void setMaxFiles(Integer maxFiles) {
+	    this.maxFiles = maxFiles;
+	}
+
+	/**
+	 * @return the width
+	 */
+	public String getWidth() {
+	    return width;
+	}
+
+	/**
+	 * @param width the width to set
+	 */
+	public void setWidth(String width) {
+	    this.width = width;
+	}
+
+	/**
+	 * @return the height
+	 */
+	public String getHeight() {
+	    return height;
+	}
+
+	/**
+	 * @param height the height to set
+	 */
+	public void setHeight(String height) {
+	    this.height = height;
+	}
 	
 	
 }
 
+

Added: trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/FileData.java
===================================================================
--- trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/FileData.java	                        (rev 0)
+++ trunk/sandbox/samples/fileUploadDemo/src/main/java/org/richfaces/FileData.java	2008-02-22 15:26:08 UTC (rev 6301)
@@ -0,0 +1,40 @@
+/*
+ * FileData.java		Date created: 22.02.2008
+ * Last modified by: $Author$
+ * $Revision$	$Date$
+ */
+
+package org.richfaces;
+
+/**
+ * TODO Class description goes here.
+ * @author "Andrey Markavtsov"
+ *
+ */
+public class FileData {
+    private String name;
+    
+   
+   
+    public FileData(String name) {
+	this.name = name;
+    }
+
+
+    /**
+     * @return the name
+     */
+    public String getName() {
+        return name;
+    }
+
+
+    /**
+     * @param name the name to set
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+  
+    
+}
\ No newline at end of file

Modified: trunk/sandbox/samples/fileUploadDemo/src/main/webapp/pages/index.jsp
===================================================================
--- trunk/sandbox/samples/fileUploadDemo/src/main/webapp/pages/index.jsp	2008-02-22 15:25:37 UTC (rev 6300)
+++ trunk/sandbox/samples/fileUploadDemo/src/main/webapp/pages/index.jsp	2008-02-22 15:26:08 UTC (rev 6301)
@@ -19,24 +19,36 @@
 </head>
 <body>
 <f:view>
+ 
 <h:form>
-	<h:selectOneRadio>
-		<f:selectItem itemLabel="1" itemValue="1"/>
-		<f:selectItem itemLabel="2" itemValue="2"/>
-	</h:selectOneRadio>
+<table cellpadding="0" cellspacing="0" style="width: 500px">
+<tr><td>Files Types:</td><td>
+<h:inputText value="#{bean.fileTypes}"></h:inputText></td></tr>
+<tr><td>Max Files Count:</td><td>
+<h:inputText value="#{bean.maxFiles}"></h:inputText></td></tr>
+<tr><td>Upload List Width:</td><td>
+<h:inputText value="#{bean.width}"></h:inputText></td></tr>
+<tr><td>Upload List Height:</td><td>
+<h:inputText value="#{bean.height}"></h:inputText></td></tr>
+</table><br/>
+<a4j:commandButton reRender="upload1" value="Accept"></a4j:commandButton>
+</h:form>
 
-	<h:selectBooleanCheckbox value="#{bean.flag}" id="boolean" />
-	
-	<h:messages />
-
-<fu:fileUpload data="#{bean.data}" fileUploadListener="#{bean.listener}" listWidth="600px" listHeight="150px"
+<h:form>
+<fu:fileUpload 
+		id="upload1"
+		data="#{bean.data}" 
+		fileUploadListener="#{bean.listener}" 
+		listWidth="#{bean.width}px" 
+		listHeight="#{bean.height}px"
 		uploadListClass="list"
 		uploadListClassDisabled="list_disabled"
 		fileEntryClass="entry"
 		fileEntryClassDisabled="entry_disabled"
 		fileEntryControlClass="entry_control"
 		fileEntryControlClassDisabled="entry_control_disabled"
-		maxFilesQuantity="4">
+		maxFilesQuantity="#{bean.maxFiles}"
+		acceptedTypes="#{bean.fileTypes}">
 	<f:facet name="progress">
 		<progressBar:progressBar style="height: 10px; width: 300px;">
 		</progressBar:progressBar>
@@ -45,10 +57,16 @@
 		<h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}"></h:outputText>
 	</f:facet>
 </fu:fileUpload><br/><br/><br/>
-<h:commandButton actionListener="#{bean.action}" style="font-weight: bold; width: 300px;" value="Print file content in console"></h:commandButton>
-<br/>
-<input type="button" onclick="$('j_id_jsp_223736782_1:j_id_jsp_223736782_7').component.enable();" value="Enable" />
-<input type="button" onclick="$('j_id_jsp_223736782_1:j_id_jsp_223736782_7').component.disable();" value="Disable" /><br/>
+<a4j:commandLink style="font-weight: bold; width: 200px;" value="Show files uploaded:" reRender="files_list"></a4j:commandLink><br/><br/>
+<h:dataTable value="#{bean.fileList}" var="file" id="files_list" style="width: 500px">
+	<h:column>
+	<h:outputText value="#{file.name}"></h:outputText>	
+	</h:column>
+</h:dataTable>
+
+<br/><br/><br/>
+<input type="button" onclick="$('j_id_jsp_223736782_7:upload1').component.enable();" value="Enable" />
+<input type="button" onclick="$('j_id_jsp_223736782_7:upload1').component.disable();" value="Disable" /><br/>
 </h:form>
 </f:view>
 </body>




More information about the richfaces-svn-commits mailing list