This content has been marked as final.
Show 5 replies
-
1. Re: Dynamic file upload data turn to null
ilya_shaikovsky Mar 27, 2009 5:09 AM (in response to panky_p)provide more information like page and bean code used, environment info, web.xml and steps performed on the page.
-
2. Re: Dynamic file upload data turn to null
panky_p Mar 27, 2009 6:20 AM (in response to panky_p)Hi Ilya,
I am using Seam 2.1.0.SP1 and RF 3.2.2.SR1
my upload listener is in EditBeanpublic void fileUploadListener(UploadEvent event) throws IOException { UploadItem uploadItem = event.getUploadItem(); HtmlFileUpload htmlFileUpload = (HtmlFileUpload)event.getSource(); if (uploadItem.isTempFile()){ try{ FileUploadBean fileUploadBean = new FileUploadBean(); File file = uploadItem.getFile(); FileInputStream fs = new FileInputStream(file); int numberBytes = fs.available(); byte bytearray[] = new byte[numberBytes]; fs.read(bytearray); fileUploadBean.setData(bytearray); fileUploadBean.setFileName(uploadItem.getFileName()); fileUploadBean.setContentType(uploadItem.getContentType()); htmlFileUpload.setUploadData(fileUploadBean); fis.close(); }catch(FileNotFoundException fnf){ }catch(IOException ioe){ }catch(Exception ex){ } } }
and my component bean contains following code for file uploadHtmlFileUpload newFileUpload = new HtmlFileUpload(); String fileUploadId = "upload_file"; newFileUpload.setId(fileUploadId); newFileUpload.setAddControlLabel("Select"); newFileUpload.setListWidth("300"); newFileUpload.setListHeight("300"); newFileUpload.setMaxFilesQuantity(1); newFileUpload.setImmediateUpload(true); newFileUpload.setAjaxSingle(true); MethodBinding fileUploadListener = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{editBean.fileUploadListener}", new Class[] {UploadEvent.class}); newFileUpload.setFileUploadListener(uploadListener);
and in web.xml i had<context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <filter> <filter-name>Seam Filter</filter-name> <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class> <init-param> <param-name>createTempFiles</param-name> <param-value>false</param-value> </init-param> </filter>
Please tell me where i am wrong!! -
3. Re: Dynamic file upload data turn to null
ilya_shaikovsky Mar 27, 2009 6:28 AM (in response to panky_p)so you defined
<init-param> <param-name>createTempFiles</param-name> <param-value>false</param-value> </init-param>
and trying to use fileif (uploadItem.isTempFile()){ .. File file = uploadItem.getFile();
it's wrong. -
4. Re: Dynamic file upload data turn to null
panky_p Mar 27, 2009 6:41 AM (in response to panky_p)Thanks for quick reply!!
I did changes to<init-param> <param-name>createTempFiles</param-name> <param-value>true</param-value> </init-param>
but still I am getting the same behavior. -
5. Re: Dynamic file upload data turn to null
ilya_shaikovsky Mar 27, 2009 7:06 AM (in response to panky_p)so could you just debug your listener and check where the problem is. We have normal saving using both methods as you could see from our samples.