1 16 package org.apache.myfaces.examples.misc; 17 18 import java.io.IOException ; 19 20 import org.apache.myfaces.custom.fileupload.UploadedFile; 21 22 import javax.faces.context.FacesContext; 23 24 28 public class FileUploadForm 29 { 30 private UploadedFile _upFile; 31 private String _name = ""; 32 33 public UploadedFile getUpFile() 34 { 35 return _upFile; 36 } 37 38 public void setUpFile(UploadedFile upFile) 39 { 40 _upFile = upFile; 41 } 42 43 public String getName() 44 { 45 return _name; 46 } 47 48 public void setName(String name) 49 { 50 _name = name; 51 } 52 53 public String upload() throws IOException 54 { 55 FacesContext facesContext = FacesContext.getCurrentInstance(); 56 facesContext.getExternalContext().getApplicationMap().put("fileupload_bytes", _upFile.getBytes()); 57 facesContext.getExternalContext().getApplicationMap().put("fileupload_type", _upFile.getContentType()); 58 facesContext.getExternalContext().getApplicationMap().put("fileupload_name", _upFile.getName()); 59 return "ok"; 60 } 61 62 public boolean isUploaded() 63 { 64 FacesContext facesContext = FacesContext.getCurrentInstance(); 65 return facesContext.getExternalContext().getApplicationMap().get("fileupload_bytes")!=null; 66 } 67 68 } 69 | Popular Tags |