后续请求中不会清除 Faces 消息
情况如下:
你有一个解析文件的bean方法,如果解析失败,则添加错误消息,如果解析成功,则添加成功消息。
但是当你连续操作时:fail > success ,我希望失败消息会消失并出现成功消息,但发生的情况是失败消息仍然存在,并且成功消息被添加到其中。
在添加消息之前清除 MessageList 不是一个解决方案,因为列表已经被清除,如果您尝试在添加消息之前打印消息列表大小,在这两种情况下它都将是 0。
那么在这种情况下删除失败消息的解决方案是什么成功,反之亦然?
Bean:
@Component("mybean")
@Scope("view")
public class MyBean {
try {
myservice.parseFile(file);
} catch (Exception e) {
FacesMessage msg = new FacesMessage();
msg.setSeverity(FacesMessage.SEVERITY_FATAL);
msg.setSummary("Invalid file.");
facesContext.addMessage(null, msg);
return;
}
FacesMessage msg = new FacesMessage();
msg.setSeverity(FacesMessage.SEVERITY_INFO);
msg.setSummary("Success");
facesContext.addMessage(null, msg);
}
查看:
<h:form>
<ace:fileEntry id="fileEntryComp"
label="File Entry"
relativePath="uploaded"
fileEntryListener="#{mybean.listener}" />
<h:commandButton value="Upload File" />
<h:messages styleClass="myclass" infoStyle="Color:blue;" errorStyle="Color:red;" fatalStyle="margin-right: 85%; Color:red;" globalOnly="true"/>
<h:messages for="fileEntryComp" style="display:none;"/> <!-- to hide the faces development message-->
</h:form>
更新:
我什至尝试了这里的解决方法:
以在添加新消息之前清除消息 div,但没有新消息,我不知道他从哪里得到旧消息。
更新2:
我什至尝试了这里提到的两种解决方法:
http://www.icefaces.org/JForum/posts/list/19753.page#71521
1- 添加上下文param:
<context-param>
<param-name>org.icefaces.messagePersistence</param-name>
<param-value>false</param-value>
</context-param>
也不起作用。
2-清除保存的全局消息集合:
我尝试了这个解决方案:
List<FacesMessage> globals = (List<FacesMessage>) facesContext.getViewRoot().getAttributes().get("org.icefaces.event.saved_global_faces_messages");
if (globals != null) {
globals.clear();
}
但我总是遇到以下异常:
Caused by: java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.clear(Collections.java:1037)
at com.xeno.phoneSuite.beans.DepartmentBean.listener(DepartmentBean.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at org.icefaces.component.fileentry.FileEntry.broadcast(FileEntry.java:311)
... 92 more
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最后,我在最新版本ICEfaces 2.1 Beta 2上尝试了上下文参数的解决方案,它工作正常:
http://wiki.icefaces.org/display/ICE/ICEfaces+2.1.0+Beta+2+Release+Notes#ICEfaces2.1.0Beta2ReleaseNotes-downloads
希望有所帮助。
finally, i tried the solution of the context param on the latest version ICEfaces 2.1 Beta 2 and it works fine:
http://wiki.icefaces.org/display/ICE/ICEfaces+2.1.0+Beta+2+Release+Notes#ICEfaces2.1.0Beta2ReleaseNotes-downloads
hope that will helps.
我在 Icefaces 3.3 中也遇到了类似的问题。我使用以下代码解决了这个问题(哦,顺便说一句,我还看到 @BalusC 已经在他的评论中指出了这样的解决方案):
在推送像这样的新消息之前放置上面的代码,应该清除旧消息并替换它新消息
我的消息
:I am in Icefaces 3.3 and had a similar problem. I solved this using the following code (Oh BTW I also see that @BalusC has already pointed out such a solution in his comments):
Putting above piece of code before pushing a new message like this one, should clear your old message and replace it with the new message
My Message
:我费了很大劲,最后修复很简单,无论是素脸还是旧脸,只需添加 redisplay = false 即可。
下面是代码片段。
I struggled a lot and finally the fix was very simple whether it is prime faces or old faces, just add redisplay = false.
Below is the snippet of the code.