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 2016/01/21 11:32:26 UTC
svn commit: r1725898 - in /myfaces/tobago/branches/tobago-3.0.x: ./
tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/
tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/
Author: lofwyr
Date: Thu Jan 21 10:32:26 2016
New Revision: 1725898
URL: http://svn.apache.org/viewvc?rev=1725898&view=rev
Log:
Merged from trunk
upload with validation [from revision 1725894]
Modified:
myfaces/tobago/branches/tobago-3.0.x/ (props changed)
myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java
myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/UploadItem.java
myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml
Propchange: myfaces/tobago/branches/tobago-3.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jan 21 10:32:26 2016
@@ -1,3 +1,3 @@
/myfaces/tobago/branches/tobago-1.5.x:1356585,1357124
/myfaces/tobago/branches/tobago-tree-table:1226794-1341423
-/myfaces/tobago/trunk:1571193,1571804,1571816,1571941,1571945,1571962,1571966,1576730,1589960,1591854,1600239,1600818,1601860,1602151,1602154,1602343,1604224,1606201,1607642,1609696-1609697,1609718,1610942,1610948,1610970,1610989,1611011,1611259,1611264,1611276,1611329,1611338-1611339,1611571,1613015,1613032,1614827,1614853,1615053,1615114,1615121,1617310,1619789,1621101,1621107,1621134,1621156,1621264,1621282,1621332,1622222,1622243,1622508,1623934,1624033,1625968,1625972,1626270,1628899,1628953,1636842,1636911,1640117,1640147,1640541,1640548,1640638,1640761,1640917,1641575,1641635,1641772,1641775,1641777,1656502,1656507,1657180,1657269,1657276,1657279,1658343,1658909,1658912,1659026,1659031,1660696,1660699,1660708,1660714,1665486,1665521,1665549,1665569-1665570,1666464,1667304,1667306-1667307,1667309,1668147,1668153,1668249,1675330,1675565,1675584,1675588-1675589,1675636,1676030,1676035,1676038,1679031,1680197,1681981,1682187,1682448,1682545,1682548,1683231,1683306,1683373,1683664
,1686204,1687354,1693426,1696720,1698292,1698297,1700742,1700795,1701249,1701251,1701256,1701980,1709006
+/myfaces/tobago/trunk:1571193,1571804,1571816,1571941,1571945,1571962,1571966,1576730,1589960,1591854,1600239,1600818,1601860,1602151,1602154,1602343,1604224,1606201,1607642,1609696-1609697,1609718,1610942,1610948,1610970,1610989,1611011,1611259,1611264,1611276,1611329,1611338-1611339,1611571,1613015,1613032,1614827,1614853,1615053,1615114,1615121,1617310,1619789,1621101,1621107,1621134,1621156,1621264,1621282,1621332,1622222,1622243,1622508,1623934,1624033,1625968,1625972,1626270,1628899,1628953,1636842,1636911,1640117,1640147,1640541,1640548,1640638,1640761,1640917,1641575,1641635,1641772,1641775,1641777,1656502,1656507,1657180,1657269,1657276,1657279,1658343,1658909,1658912,1659026,1659031,1660696,1660699,1660708,1660714,1665486,1665521,1665549,1665569-1665570,1666464,1667304,1667306-1667307,1667309,1668147,1668153,1668249,1675330,1675565,1675584,1675588-1675589,1675636,1676030,1676035,1676038,1679031,1680197,1681981,1682187,1682448,1682545,1682548,1683231,1683306,1683373,1683664
,1686204,1687354,1693426,1696720,1698292,1698297,1700742,1700795,1701249,1701251,1701256,1701980,1709006,1725894
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java?rev=1725898&r1=1725897&r2=1725898&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/Upload.java Thu Jan 21 10:32:26 2016
@@ -23,29 +23,33 @@ import org.apache.commons.fileupload.Fil
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.faces.application.FacesMessage;
-import javax.faces.context.FacesContext;
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Named;
+import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-public class Upload {
+@SessionScoped
+@Named
+public class Upload implements Serializable {
private static final Logger LOG = LoggerFactory.getLogger(Upload.class);
- private FileItem file;
+ private FileItem file1;
+ private FileItem file2;
private List<UploadItem> list = new ArrayList<UploadItem>();
public String upload() {
- if (file == null) {
- FacesContext.getCurrentInstance().addMessage(
- null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "No UploadItem found!", null));
- return null;
- }
- if (file.get().length == 0) {
- FacesContext.getCurrentInstance().addMessage(
- null, new FacesMessage(FacesMessage.SEVERITY_WARN, "Empty UploadItem found!", null));
- return null;
+ upload(file1);
+ upload(file2);
+ return null;
+ }
+
+ public void upload(FileItem file) {
+ LOG.info("checking file item");
+ if (file == null || file.get().length == 0) {
+ return;
}
LOG.info("type=" + file.getContentType());
LOG.info("size=" + file.get().length);
@@ -58,16 +62,22 @@ public class Upload {
}
LOG.info("name=" + name);
list.add(new UploadItem(name, file.get().length, file.getContentType()));
- file = null; // we don't need it in this demo.
- return null;
}
- public FileItem getFile() {
- return file;
+ public FileItem getFile1() {
+ return file1;
+ }
+
+ public void setFile1(FileItem file1) {
+ this.file1 = file1;
+ }
+
+ public FileItem getFile2() {
+ return file2;
}
- public void setFile(final FileItem file) {
- this.file = file;
+ public void setFile2(FileItem file2) {
+ this.file2 = file2;
}
public List<UploadItem> getList() {
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/UploadItem.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/UploadItem.java?rev=1725898&r1=1725897&r2=1725898&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/UploadItem.java (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/UploadItem.java Thu Jan 21 10:32:26 2016
@@ -22,7 +22,9 @@ package org.apache.myfaces.tobago.exampl
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class UploadItem {
+import java.io.Serializable;
+
+public class UploadItem implements Serializable {
private static final Logger LOG = LoggerFactory.getLogger(UploadItem.class);
Modified: myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml?rev=1725898&r1=1725897&r2=1725898&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml (original)
+++ myfaces/tobago/branches/tobago-3.0.x/tobago-example/tobago-example-demo/src/main/webapp/content/40-upload/upload.xhtml Thu Jan 21 10:32:26 2016
@@ -23,22 +23,13 @@
xmlns:f="http://java.sun.com/jsf/core">
<ui:param name="title" value="File Upload"/>
<tc:panel>
- <f:facet name="layout">
- <tc:gridLayout rows="auto;*"/>
- </f:facet>
-
- <tc:panel>
- <f:facet name="layout">
- <tc:gridLayout columns="*;auto"/>
- </f:facet>
-
- <tc:file label="Upload file:" value="#{upload.file}">
- <!-- todo: write a 2nd example to demonstrate validation
- <tc:validateFileItem contentType="image/gif image/png"/>
- -->
- </tc:file>
- <tc:button label="Submit" defaultCommand="true" action="#{upload.upload}"/>
- </tc:panel>
+
+ <tc:file label="Upload file:" value="#{upload.file1}" tip="without extra validation" id="file1"/>
+ <tc:file label="Upload image:" value="#{upload.file2}" id="file2"
+ tip="with a validator for file items - types: gif, jpg, png">
+ <tc:validateFileItem contentType="image/*"/>
+ </tc:file>
+ <tc:button label="Submit" defaultCommand="true" action="#{upload.upload}"/>
<tc:sheet var="entry" value="#{upload.list}" columns="*;*;*">
@@ -55,5 +46,6 @@
</tc:column>
</tc:sheet>
+
</tc:panel>
</ui:composition>