Seam+RichFaces fileUpload 应该引发重新渲染
我正在使用 RichFaces 3.3 和 Seam 2 来开发 Web 应用程序。
我有一个包含以下内容的页面:
<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>
在 service.uploadEvent
方法中,我接收文件并添加 FacesMessage 让用户知道文件已成功上传。
实际发生的情况是这样的:
- 浏览器请求页面
- 服务器开始临时会话#1
- 服务器渲染页面
- 服务器发送完成的页面并终止会话#1
- 客户端启动 AJAX fileUpload 调用
- 服务器开始临时对话#2
- 服务器调用
service.fileUpload()
。此方法将FacesMessage
添加到对话范围的FacesMessages
接缝组件。 - 服务器返回 AJAX 请求的响应并终止会话 #2,包括所有排队的
FacesMessage
。
- 收到“onuploadcomplete”事件,客户端请求重新渲染“myPanel”
- 服务器开始临时会话#3
- 服务器呈现页面,为对话 #3 创建一个新的空
FacesMessages
- 服务器返回 AJAX 请求的响应(其中包含空的
)并终止会话 #3
我可以通过多种方式解决这个问题:
- 通过创建一个新的 PAGE 范围的 FacesMessages 组件。
- 通过在
service.fileUpload()
中将对话标记为长时间运行,并在执行fileUploadComplete()
时结束对话。
正确的方法是在与 service.fileUpload()
相同的会话中重新渲染页面。这可能吗?
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 aFacesMessage
to the Conversation-scopedFacesMessages
seam component. - The server returns the response for the AJAX request and kills conversation #2, including all queued
FacesMessage
s.
- 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
FacesMessages
for 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这只能通过使用自定义 StatusMessages 组件并将其范围限定在重新渲染上仍然可用的上下文(例如页面或长时间运行的对话)来解决。
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).
您是否尝试过用
替换
?当 AJAX 操作创建新的 FacesMessage 时,它效果很好。请参阅http://docs.jboss.org/richfaces/latest_3_3_X/ en/devguide/html/rich_messages.htmlHave you tried replacing
<h:messages />
with<rich:messages />
? It works well when AJAX actions create new FacesMessages. See http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/rich_messages.html