Author: ilya_shaikovsky
Date: 2008-03-25 13:46:16 -0400 (Tue, 25 Mar 2008)
New Revision: 7221
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/fileUpload/File.java
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/fileUpload/FileUploadBean.java
trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
trunk/samples/richfaces-demo/src/main/webapp/richfaces/fileUpload/examples/fileUpload.xhtml
Log:
fileUpload example creation.
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/fileUpload/File.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/fileUpload/File.java 2008-03-25
17:37:40 UTC (rev 7220)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/fileUpload/File.java 2008-03-25
17:46:16 UTC (rev 7221)
@@ -3,25 +3,17 @@
public class File {
private String Name;
- private int length;
- private byte[] data;
+ private long length;
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
- public int getLength() {
+ public long getLength() {
return length;
}
- public void setLength(int length) {
+ public void setLength(long length) {
this.length = length;
}
- public byte[] getData() {
- return data;
- }
- public void setData(byte[] data) {
- this.data = data;
- }
-
}
Modified:
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/fileUpload/FileUploadBean.java
===================================================================
---
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/fileUpload/FileUploadBean.java 2008-03-25
17:37:40 UTC (rev 7220)
+++
trunk/samples/richfaces-demo/src/main/java/org/richfaces/demo/fileUpload/FileUploadBean.java 2008-03-25
17:46:16 UTC (rev 7221)
@@ -3,9 +3,7 @@
*/
package org.richfaces.demo.fileUpload;
-import java.awt.Graphics2D;
import java.io.IOException;
-import java.io.OutputStream;
import java.util.ArrayList;
import org.richfaces.event.UploadEvent;
@@ -15,33 +13,36 @@
* @author Ilya Shaikovsky
*
*/
-public class FileUploadBean {
+public class FileUploadBean{
private ArrayList<File> files = new ArrayList<File>();
+ public int getSize() {
+ if (getFiles().size()>0){
+ return getFiles().size();
+ }else
+ {
+ return 0;
+ }
+ }
+
public FileUploadBean() {
}
public void listener(UploadEvent event) throws IOException{
UploadItem item = event.getUploadItem();
- System.out.println("FileUploadBean.listener()");
File file = new File();
file.setLength(item.getData().length);
file.setName(item.getFileName());
- file.setData(item.getData());
- files.add(file);
+ files.add(file);
}
- public void paint(OutputStream outputStream, Object obj) throws IOException {
- outputStream.write((byte[])obj);
- System.out.println("FileUploadBean.paint()");
- }
-
public ArrayList<File> getFiles() {
return files;
}
- public void setFiles(ArrayList<File> files) {
+ public void setFiles(ArrayList<File> files) {
this.files = files;
}
+
}
Modified: trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml 2008-03-25
17:37:40 UTC (rev 7220)
+++ trunk/samples/richfaces-demo/src/main/webapp/WEB-INF/faces-config.xml 2008-03-25
17:46:16 UTC (rev 7221)
@@ -296,7 +296,7 @@
<managed-bean>
<managed-bean-name>fileUploadBean</managed-bean-name>
<managed-bean-class>org.richfaces.demo.fileUpload.FileUploadBean</managed-bean-class>
- <managed-bean-scope>session</managed-bean-scope>
+ <managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>sortingBean</managed-bean-name>
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/fileUpload/examples/fileUpload.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/fileUpload/examples/fileUpload.xhtml 2008-03-25
17:37:40 UTC (rev 7220)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/fileUpload/examples/fileUpload.xhtml 2008-03-25
17:46:16 UTC (rev 7221)
@@ -4,22 +4,44 @@
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
+
+ <style>
+ .top{
+ vertical-align:top;
+ }
+ .info{
+ height:210px;
+ overflow:auto;
+ }
+ </style>
+
+ <a4j:form>
+ <a4j:keepAlive beanName="fileUploadBean" ajaxOnly="false"/>
+ <h:panelGrid columns="2" columnClasses="top,top">
+ <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
+ maxFilesQuantity="5" reRender="table">
+ <a4j:support event="onuploadcomplete"
reRender="table"></a4j:support>
+ </rich:fileUpload>
- <a4j:form>
- <rich:fileUpload fileUploadListener="#{fileUploadBean.listener}"
- maxFilesQuantity="5" reRender="table">
- <a4j:support event="onuploadcomplete"
reRender="table"></a4j:support>
- </rich:fileUpload>
- <rich:dataTable value="#{fileUploadBean.files}" var="file"
id="table">
- <rich:column>
- <h:outputText value="#{file.name}"></h:outputText>
- </rich:column>
- <rich:column>
- <h:outputText value="#{file.length}"></h:outputText>
- </rich:column>
- <rich:column>
- <a4j:mediaOutput createContent="#{fileUploadBean.paint}"
value="file.data" mimeType="image/jpeg" element="img"/>
- </rich:column>
- </rich:dataTable>
+ <rich:panel bodyClass="info" id="table">
+ <f:facet name="header">
+ <h:outputText value="Uploaded Files Info" />
+ </f:facet>
+ <h:outputText value="No files currently uploaded"
rendered="#{fileUploadBean.size==0}"></h:outputText>
+ <rich:dataGrid columns="1" value="#{fileUploadBean.files}"
+ var="file">
+ <rich:panel>
+ <h:panelGrid columns="2">
+ <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>
+ </h:panelGrid>
</a4j:form>
</ui:composition>
\ No newline at end of file