#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2012
    Posts
    1
    Rep Power
    0

    Send string(file name) to other class


    Hi i have a little problem
    I have a two class Upload - class upload file to server and class filter
    but now in class filter i need name uploaded file i try something like this:

    class upload:

    Code:
    public class uploadclass {
    
    	private UploadedFile uploadedFile;
            private String fileName;
        
        public String submit() {
    	String prefix = FilenameUtils.getBaseName(uploadedFile.getName());
            String suffix = FilenameUtils.getExtension(uploadedFile.getName());
            
            
            File file = null;
            OutputStream output = null;
            
            try {
                file = File.createTempFile(prefix , "." + suffix, new File("c:/upload"));
            	
                output = new FileOutputStream(file);
                IOUtils.copy(uploadedFile.getInputStream(), output);
                
                fileName = file.getName();
                filter fil=new filter();
               fil.setNazwa(fileName);
                
                System.out.println(fileName);
                
            } catch (IOException e) {
               if (file != null) file.delete();
               FacesContext.getCurrentInstance().addMessage("uploadForm", new FacesMessage(
               FacesMessage.SEVERITY_ERROR, "File upload failed with I/O error.", null));
               e.printStackTrace();
            }
            finally {
                IOUtils.closeQuietly(output);
             }
            return "success";
        }
       public UploadedFile getUploadedFile() {
            return uploadedFile;
        }
        public  String getFileName() {
        	return fileName;
        }
        public void setUploadedFile(UploadedFile uploadedFile) {
            this.uploadedFile = uploadedFile;
        }
    	
    }
    this:
    fileName = file.getName();
    filter fil=new filter();
    fil.setNazwa(fileName);


    And filter class
    Code:
    public class filter {
    	private String name;
    	public String filename;
    	
    	public void aaa(){
    	        filename=getName();
    		System.out.println(filename);
    	}
    	public void setName(String name) {
    	      this.name = name;
    	 }
    	 public String getName() {
    	      return name;
    	 }
    	
    }

    When System.out.println(filename); is execute i have filename on console null;
    submit() and aaa() is active on buttonclick
    what i doing wrong?
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347

IMN logo majestic logo threadwatch logo seochat tools logo