You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 14 Members of 8188 |
| Forum: Seam Users |
01. Apr 2008, 14:47 CET | Link |
Hi, I upgraded to Richfaces 3.2.0 today and I believe there are some problems with the multipart request for the new fileupload component.
I have tried getting it all to work with the fileUploadDemo in the richfaces src, with minimal code modifications. (Only added @Name(fileUploadBean
) @Scope(ScopeType.CONVERSATION) and added fileUpload.xhtml to pages.xhtml with action starting a new conversation)
First I tried with my normal setup which works fine with s:fileUpload using the web multipart filter.
<web:multipart-filter create-temp-files="true" max-request-size="20485760" url-pattern="*.seam" />
This results in the correct listener being called
public void listener(UploadEvent event) throws IOException
but data in event.uploadItem is null. Then I tried with
<web:ajax4jsf-filter force-parser="true" enable-cache="false" url-pattern="*.seam" />
which made the upload component useless, due to no scripts/css being served at all(seam bug? richfaces bug?). However I managed to cache the script/css at one time and make a submit, which also had date = null;
I quick look at the richfaces trunk showed that there has been some multipart request additions in their code, that might be essential for this component to work.
I guess s:fileUpload / rich:fileUpload may be in collision, but, for me at least, getting rich;fileUpload to work would be really nice, if anyone could help.
The demo runs perfectly outside seam environment(however, it has a few bugs for the richfaces team to solve)
I found MultipartFilter.java in the richfaces trunk, but is seem's a bit
/** * A filter for decoding multipart requests, for * use with the file upload control. * * @author Shane Bryzak * */ //@Scope(APPLICATION) //@Name("org.jboss.seam.web.multipartFilter") //@Install(precedence = BUILT_IN) //@BypassInterceptors //@Filter(within={"org.jboss.seam.web.ajax4jsfFilter", "org.jboss.seam.web.exceptionFilter"}) public class MultipartFilter implements FilterInstalled Shanes filter (precedence > BUILT_IN), same result. Data is null.
im right behind you implementing this new fileupload component. i read somewhere on the richfaces board last night,, that multipart wasnt needed for this. just h:form.. i guess im about a day behind you.. so im watching your progress with great anticipation .
'Why don't you try using logical logic this time. That's a plan that should work.'
This works for me
public void listener(UploadEvent event) throws IOException { UploadItem item = event.getUploadItem(); String name = "unnamed_attachment"; byte[] data = item.getData(); if (item.isFile()) { name = FilenameUtils.getName(item.getFileName()); data = FileUtils.readFileToByteArray( item.getFile() ); } debug("file uploaded '#0' : '#1'", name, item.getFileName()); ... ...Works for me too. Thanks!
I'm with similar problem, but in my case listener method isn't called.
I'm using Seam 2.0.2 CR1. My configurations are pretty similar. What can be?
Marcos Sousa marcossousa.com Enjoy it!
I'm using RichFaces 3.2.1-SNAPSHOT, Seam 2.0.1-GA and Facelets.
I try to use the rich:fileUpload component to upload 5 pictures at once. This is from my editImageSet.xhtml page:
<rich:fileUpload fileUploadListener="#{imageSetView.imageUploadListener}" maxFilesQuantity="5" id="upload" acceptedTypes="jpg, jpeg, gif, png"> <a:support event="onuploadcomplete" reRender="currentImageSetA, messagesA" /> </rich:fileUpload>The editImageSet.xhtml page is called like this: <s:link action="#{imageSetView.editImageSet(imageSet)}" view="editImageSet.xhtml" value="edit"/>, so it starts a new CONVERSATION when entering the page.
And this is my listener:
@Stateful @AutoCreate @Name("imageSetView") @Scope(ScopeType.CONVERSATION) public class ImageSetViewBean implements LocalImageSetView { ... @In private EntityManager entityManager; private ImageSet currentImageSet; @Begin(join = true) public void editImageSet(ImageSet selectedImageSet) { setCurrentImageSet(imageSetDAO.findImageSetById( selectedImageSet.getId() )); setImages(currentImageSet.getImages()); log.info("images= #0", getImages()); } // also tried without the @Begin // also tried with @Begin(join = true) @Begin(nested = true) public void imageUploadListener(org.richfaces.event.UploadEvent event) throws IOException { if (event == null) { log.warn("imageUploadListener(): null upload event"); return; } org.richfaces.model.UploadItem item = event.getUploadItem(); if(item.isFile()) { java.io.File tempFile = item.getFile(); fileName = tempFile.getAbsolutePath(); // --- // --- some image copying, resizing that was removed from this forum post --- // --- try { Image db_main = new Image(); db_main.setUrl(fileName); log.info("em= #0, db_main= #1", entityManager, db_main); entityManager.persist(db_main); currentImageSet.getImages().add(db_main); entityManager.merge(currentImageSet); } catch(Throwable t) { t.printStackTrace(); return; } } log.info("Image uploaded."); } ... }Well, the problem is when it comes to the entityManager.persist(db_main) line. It jumps out to the /home.xhtml page saying that . If I comment the lines that deal with the database (persist, merge) everything works well, all 5 files are uploaded, resized, moved.
The interesting thing is that the first file (image) uploaded is saved on disk, and even persisted. And it is even added to the currentImageSet. So the method works well just for the first file.
Could anyone please tell me why is the imageUploadListener() method ending my conversation the first time it is called?
Thank you in advance for any hint,
Bogdan.
I'm having the same problem with Richfaces 3.2.0.GA, Seam 2.0.1.GA and I'm using Facelets also. I'm also forwarded to the home page defined in the pages.xml descriptor.
When I check for the conversation, then it's still active and available. I encountered these problems sometimes also with the default onblur validation for the input components. When I saved the form I was always forwarded to the no-conversation-view-id page . I still have that problem and no fix for both yet.
My upload file data from the Richfaces fileUpload is also null, but I can read it directly from the filesystem because I can get the uploaded filename.
I hope anyone can give help on that.
One more with the same problem!
rich:fileUpload ends conversation in Seam
Uros
I solved this problem by modifying the concurrent-request-timeout value from:
<core:manager concurrent-request-timeout="500" conversation-timeout="120000" conversation-id-parameter="cid"/> to
<core:manager concurrent-request-timeout="5000" conversation-timeout="180000" conversation-id-parameter="cid"/>
Thanks to Zahid: http://www.seamframework.org/Community/RichfileUploadListenerIsJumpingOutOfTheConversation
Hello All,
I'm running into a problem also where I'm getting null for the filename and size. However, upon close inspection the file is actually being written to the temp location on the servers' hard drive with an autogenerated filename.
I'm pretty much at a loss as to why the attributes of the UploadItem are not being populated.
Details are below. Any assistance would be greatly appreciated!
Sean
I've disabled the normal Multipart Filter in the components.xml using:
<web:multipart-filter create-temp-files="true" max-request-size="1000000" url-pattern="*.seam" disabled="true" />We are using facelet's and this is the snippet from the page:
<a4j:form> <rich:fileUpload id="upload1" uploadData="#{uploadAction2.data}" fileUploadListener="#{uploadAction2.listener}" listWidth="#{uploadAction2.width}" listHeight="#{uploadAction2.height}" maxFilesQuantity="#{uploadAction2.maxFiles}" acceptedTypes="#{uploadAction2.fileTypes}"> <f:facet name="label"> <h:outputText value="{_KB}KB from {KB}KB uploaded --- {mm}:{ss}"> </h:outputText> </f:facet> </rich:fileUpload> ...And this is the fragment from the listener:
@Stateful @AutoCreate @Name("uploadAction2") @Scope(ScopeType.CONVERSATION) @Synchronized public class UploadActionBean2 implements UploadAction2 { ... public void listener(UploadEvent event) throws IOException { try { UploadItem item = event.getUploadItem(); String name = "unnamedattachment"; byte[] data = item.getData(); if (item.isFile()) { name = FilenameUtils.getName(item.getFileName()); data = FileUtils.readFileToByteArray( item.getFile() ); } else { ByteArrayOutputStream b = new ByteArrayOutputStream(); b.write(item.getData()); System.out.println(b.toString()); } System.out.println("file uploaded " + name + " : " + item.getFileName()); } catch (Exception e) { System.out.println("FileUpload Listener Exception"); e.printStackTrace(); } } ...The results of the SOP is: file uploaded unnamedattachement : null
An exception is also thrown when it fails the item.isFile() and attempts to read from a ByteArrayOutputStream:
Found the problem.
We recently upgraded to SEAM 2.0 and still had the web.xml configured for SEAM 1.2 After going through and removing the RichFaces specific filters the FileUpload component started working.
Sean
Silly question: Does the UploadActionBean2 bean need to be a statless session bean or can it be a POJO so that we can continue using a war for hotdeployment?
So forgive me,
but can someone actually shed some light on what actually makes this component work??
I've spent 2 hours following threads and still get a null data upon upload.. :(
I have all the above code and configuration mentioned but it still doesn't work.
Troy
hi,
ive got the same problem dataa null at uploadlistener method. to solved it i just modify my web xml following this :
http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/faq/faq.html
and see rich:fileUpload with Seam
i hope it helps.
I've tried everything but item is null in sfsb
web.xml
<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> <init-param> <param-name>maxRequestSize</param-name> <param-value>200000</param-value> </init-param> </filter>facelets
<rich:fileUpload id="uploadBox" addControlLabel="Add file..." styleClass="attachDocsEnabled" stopEntryControlLabel="Stop upload" uploadControlLabel="Upload file" fileUploadListener="#{attachmentTab.listener}" maxFilesQuantity="1" listHeight="65" listWidth="610" immediateUpload="true"> <a4j:support event="onuploadcomplete" reRender="attachmentsList"/> <f:facet name="label"> <h:outputText value="{_KB}KB from {MB}MB uploaded --- {mm}:{ss}" /> </f:facet> </rich:fileUpload>sfsb
public void listener(UploadEvent event) throws IOException { UploadItem item = event.getUploadItem(); byte[] data = item.getData(); Attachment attachment = new Attachment(); // null pointer! item is null attachment.setAttachment(data); deal.addAttachment(attachment); }PL suggest!
Revert To Console
All problems with that component keeps in that code
Don't use method getData()!!! Just try get item.getFile() and than transform it to ByteArray.
Hey,
Let me clarify this for you,
When the filter parameter
createTempFiles is set to 'true' that means the component saves the file as a temporary file, so the file would be accessible through
UploadItem.getFile() , UploadItem.isTempFile() set to true
when the filter parameter is set to false the data would be available through UploadItem.getData().
Do not forget that you have to set this parameter as a seam parameter which will set the Ajax4Jsf Filer when seam starts up,
(Check this link: http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/faq/faq.html)
Regards,
Asaf.
Heyyy guys, I av som trouble with rich:fileUpload and seam configuration. I have tried many ways to point the debugger to the listener in action bean but i couldnt manage. I am using facelets 1.1.14 and richfaces 3.3.0.GA and seam 2.1.1GA.
My codes are shown below. I need ur suggestions...
<h:form enctype="multipart/form-data"> <rich:fileUpload fileUploadListener="#{fileUploadHome.listener}" maxFilesQuantity="1" addControlLabel="Ekle" progressLabel="yükleniyor..." uploadControlLabel="Yükle" clearControlLabel="Sil" stopControlLabel="Durdur" stopEntryControlLabel="İşlemi Durdur!" clearAllControlLabel="Tümünü Sil" cancelEntryControlLabel="İşlemi İptal Et!" doneLabel="İşlem Tamamlandı." id="upload" acceptedTypes="txt" listHeight="65" listWidth="610" > <a4j:support event="onupload" reRender="info" /> <f:facet name="label"> <h:outputText value="{_KB}KB from {_KB}KB yüklendi --{mm}:{ss}" /> </f:facet> </rich:fileUpload> </h:form>//No Annotation used public class FileUpload{ private Long Id; private String fileName; private String fileType; private Integer length; private byte[] data;@Name("fileUploadHome") public class FileUploadHome extends EntityHome<FileUpload> { @RequestParameter Long fileUploadId; @Override public Object getId() { if (fileUploadId == null) { return super.getId(); } else { return fileUploadId; } } private ArrayList<FileUpload> files = new ArrayList<FileUpload>(); private int uploadsAvailable = 5; private boolean autoUpload = false; private boolean useFlash = false; public void listener(UploadEvent event) throws Exception { UploadItem uploadItem = event.getUploadItem(); uploadItem.getData(); java.io.File file = uploadItem.getFile(); getInstance().setLength(uploadItem.getFileSize()); int extDot = uploadItem.getFileName().lastIndexOf('.'); String fileName = uploadItem.getFileName().substring(0, extDot); getInstance().setFileName(fileName); FileUpload fileUpload = new FileUpload(); fileUpload.setLength(uploadItem.getData().length); fileUpload.setFileName(uploadItem.getFileName()); fileUpload.setData(uploadItem.getData()); files.add(fileUpload); uploadsAvailable--; } }any suggestions?
Hello Ismail, can you clarify if you are having problems using your debbuging functions within your IDE or if the action method is not being called or if it is being called but you get an exception or a faces message?
hello, I have the same problem as ismail have and the action method is not called in my case. I have seam 2.2.1 and richfaces 3.x. i have a seam-gen generated project. I have been looking for a solution. some wrote that it is about multipart filter and etc . any suggestions. I can send the code if needed.
thanks