Seam 2.2.2.a4j:mediaOutput 之后显示的最终消息
我有一个像这样的xhtml:
<a4j:outputPanel id="displayGraph" layout="block" style="clear:both; margin-top: 0px; margin-left: 80px;margin-bottom: 20px;">
<a4j:mediaOutput element="img" cacheable="false" session="false" createContent="#{generateGraph.paint}" value="#{graph}" mimeType="image/png" standby="Loading" />
</a4j:outputPanel>
<a4j:outputPanel id="errorMessage" ajaxRendered="true">
<h:messages id="messages" styleClass="message" errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"/>
</a4j:outputPanel>
我还在支持bean中有paint方法,如果该方法给出异常,它会生成消息。像这样:
public void paint(OutputStream os, Object data) {
try{
//some actions
} catch (IOException e) {
e.printStackTrace();
FacesMessages.instance().add(Severity.ERROR, "Sorry connection can not be achieved");
}
} else {
FacesMessages.instance().add(Severity.ERROR, "Sorry server does not exist");
}
}
现在消息永远不会显示。谁能告诉我我做错了什么?
提前致谢
i have an xhtml like this:
<a4j:outputPanel id="displayGraph" layout="block" style="clear:both; margin-top: 0px; margin-left: 80px;margin-bottom: 20px;">
<a4j:mediaOutput element="img" cacheable="false" session="false" createContent="#{generateGraph.paint}" value="#{graph}" mimeType="image/png" standby="Loading" />
</a4j:outputPanel>
<a4j:outputPanel id="errorMessage" ajaxRendered="true">
<h:messages id="messages" styleClass="message" errorClass="errormsg" infoClass="infomsg" warnClass="warnmsg"/>
</a4j:outputPanel>
also i have paint method in backing bean which generates message if the method gives exception. like this:
public void paint(OutputStream os, Object data) {
try{
//some actions
} catch (IOException e) {
e.printStackTrace();
FacesMessages.instance().add(Severity.ERROR, "Sorry connection can not be achieved");
}
} else {
FacesMessages.instance().add(Severity.ERROR, "Sorry server does not exist");
}
}
now the messages are never shown. could anyone kindly tell me what i am doing wrong?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FacesMessages 是一个对话范围的接缝组件。假设您正在使用临时对话,则会发生以下情况:
您可以通过在 a4j:outputPanel 中包含
#{conversation.id}
并在paint()
方法中记录对话 ID 来对此进行测试。这个问题有两种解决方案。要么开始一个长时间运行的对话,然后添加到您的 mediaOutput 中。另一个解决方案是不使用 FacesMessages,而是使用自定义的 PAGE 范围组件来保存消息。
您还可以切换到 RichFaces4,它为每个 richfaces 组件包含一个“渲染”参数,这确保在与初始 mediaOutput AJAX 请求相同的请求中发出重新渲染。
FacesMessages is a conversation-scoped seam component. Supposing you are using temporary conversations, this is what happens:
You can test this by including
#{conversation.id}
in both your a4j:outputPanels, and by logging the Conversation ID in yourpaint()
method.There are two solutions to this problem. Either you start a long-running conversation, and add to your mediaOutput. The other solution is to not use FacesMessages but a custom PAGE-scoped component to keep your messages.
You can also switch to RichFaces4, which includes a "render" argument for every richfaces component, which makes sure the rerender is issued in the same request as the initial mediaOutput AJAX request.