I am using RichFaces 3.3 and Seam 2 to develop a web application.
I have a page with the following:
<h:form>
<s:div id="myPanel">
<h:messages/>
<rich:fileUpload fileUploadListener="#{service.uploadEvent}" maxFilesQuantity="1">
<a:support event="onuploadcomplete" reRender="myPanel"/>
</rich:fileUpload>
</s:div>
</h:form>
In the service.uploadEvent method, I receive the file and add a FacesMessage to let the user know the file uploaded succesfully.
What actually happens is this:
- The browser requests the page
- The server starts temporary conversation #1
- The server renders the page
- The server sends the completed page and kills conversation #1
- The client launches an AJAX fileUpload call
- The server starts temporary conversation #2
- The server calls
service.fileUpload(). This method adds aFacesMessageto the Conversation-scopedFacesMessagesseam component. - The server returns the response for the AJAX request and kills conversation #2, including all queued
FacesMessages.
- The ‘onuploadcomplete’ event is received, the client requests a reRender of ‘myPanel’
- The server starts temporary conversation #3
- The server renders the page, creates a new empty
FacesMessagesfor conversation #3 - The server returns the response for the AJAX request (which contains an empty
<h:messages/>) and kills conversation #3
I can solve this in a number of ways:
- By creating a new FacesMessages component which is PAGE-scoped.
- By marking the conversation as long-running in
service.fileUpload()and ending it upon doingfileUploadComplete().
The proper way would be to reRender the page in the same conversation as service.fileUpload(). Is this possible?
This can only be solved by using a custom StatusMessages component and scoping it to a context which will still be available on Rerender (e.g. PAGE or longrunning CONVERSATION).