You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2010/11/01 14:29:39 UTC
svn commit: r1029646 - in
/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main:
java/org/apache/myfaces/tobago/example/reference/Upload.java
java/org/apache/myfaces/tobago/example/reference/UploadItem.java
webapp/reference/upload.xhtml
Author: lofwyr
Date: Mon Nov 1 13:29:39 2010
New Revision: 1029646
URL: http://svn.apache.org/viewvc?rev=1029646&view=rev
Log:
Better demo for file upload
Added:
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/UploadItem.java
Modified:
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/Upload.java
myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/upload.xhtml
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/Upload.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/Upload.java?rev=1029646&r1=1029645&r2=1029646&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/Upload.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/Upload.java Mon Nov 1 13:29:39 2010
@@ -21,19 +21,26 @@ import org.apache.commons.fileupload.Fil
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.List;
+
public class Upload {
private static final Logger LOG = LoggerFactory.getLogger(Upload.class);
private FileItem file;
+ private List<UploadItem> list = new ArrayList<UploadItem>();
+
public String upload() {
LOG.info("type=" + file.getContentType());
LOG.info("file=" + file.get().length);
LOG.info("name=" + file.getName());
+ list.add(new UploadItem(file.getName(), file.get().length, file.getContentType()));
+ file = null; // we don't need it in this demo.
return null;
}
-
+
public FileItem getFile() {
return file;
}
@@ -41,4 +48,8 @@ public class Upload {
public void setFile(FileItem file) {
this.file = file;
}
+
+ public List<UploadItem> getList() {
+ return list;
+ }
}
Added: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/UploadItem.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/UploadItem.java?rev=1029646&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/UploadItem.java (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/reference/UploadItem.java Mon Nov 1 13:29:39 2010
@@ -0,0 +1,60 @@
+package org.apache.myfaces.tobago.example.reference;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UploadItem {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UploadItem.class);
+
+ private String name;
+ private int size;
+ private String type;
+
+ public UploadItem(String name, int size, String type) {
+ this.name = name;
+ this.size = size;
+ this.type = type;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getSize() {
+ return size;
+ }
+
+ public void setSize(int size) {
+ this.size = size;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+}
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/upload.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/upload.xhtml?rev=1029646&r1=1029645&r2=1029646&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/upload.xhtml (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-demo/src/main/webapp/reference/upload.xhtml Mon Nov 1 13:29:39 2010
@@ -30,12 +30,28 @@
</f:facet>
<tx:file label="Upload file:" value="#{upload.file}">
+<!-- todo: write a 2nd example to demonstrate validation
<tc:validateFileItem contentType="image/gif image/png"/>
+-->
</tx:file>
<tc:button label="Submit" defaultCommand="true" action="#{upload.upload}"/>
- <tc:cell/>
- <tc:cell/>
- <tc:cell/>
+ <tc:cell spanX="2">
+ <tc:sheet var="entry" value="#{upload.list}" columns="*;*;*">
+
+ <tc:column label="Name">
+ <tc:out value="#{entry.name}"/>
+ </tc:column>
+
+ <tc:column label="Type">
+ <tc:out value="#{entry.type}"/>
+ </tc:column>
+
+ <tc:column label="Size">
+ <tc:out value="#{entry.size}"/>
+ </tc:column>
+
+ </tc:sheet>
+ </tc:cell>
</tc:box>
-</ui:composition>
\ No newline at end of file
+</ui:composition>