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:
this: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); [B]fileName = file.getName(); filter fil=new filter(); fil.setNazwa(fileName);[/B] 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; } }
fileName = file.getName();
filter fil=new filter();
fil.setNazwa(fileName);
And filter class
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?