人脸消息不会在后续请求中清除 [英] Faces messages are not cleared on subsequent requests

查看:182
本文介绍了人脸消息不会在后续请求中清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况如下:

您有一个解析文件的bean方法,如果解析失败,则添加错误消息,如果解析成功,则添加成功消息.

you have a bean method which parses a file, and if parsing fail, error message is added, and if parsing successful, success message is added.

但是,当您进行连续操作时:fail> success,我希望失败消息会消失并显示成功消息,但是发生的情况是失败消息仍然存在,并且已将成功消息添加到其中.

But when you make consecutive operations: fail > success , i expect that the fail message will disappear and the success message appears, but what happens is that fail message is still there, and success message is added to it.

在添加消息之前清除MessageList并不是解决方案,因为列表已被清除,如果在两种情况下都尝试在添加消息之前打印消息列表大小,则它将为0.

Clearing the MessageList before adding the message is not a solution, because list is already cleared, if you try to print the message list size before adding the message in both cases it will be 0.

那么,成功后删除失败消息的解决方案是什么?反之亦然?

So what is the solution to remove fail message in case of success and vice versa?

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>

更新:

我在这里甚至尝试了解决方法:

i tried even the workaround here:

可以删除带有JSF的组件HTML内容

在添加新消息之前清除消息div,但是没有新消息,我不知道他从哪里得到旧消息.

to clear the messages div before adding new messages, but no new, i don't know where he gets the old message from.

UPDATE2:

我什至尝试了这里提到的两种解决方法:

i even tried the two workaround mentioned here:

http://www.icefaces.org/JForum/posts /list/19753.page#71521

1- 添加上下文参数:

<context-param>
    <param-name>org.icefaces.messagePersistence</param-name>
    <param-value>false</param-value>
</context-param> 

也不行.

2- 清除已保存的全局消息集合:

我尝试了以下解决方案:

i tried this solution:

 List<FacesMessage> globals = (List<FacesMessage>) facesContext.getViewRoot().getAttributes().get("org.icefaces.event.saved_global_faces_messages");
 if (globals != null) {
     globals.clear();
 }

但是我总是得到以下异常:

but i always get the following exception:

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

推荐答案

最后,我在最新版本的 ICEfaces 2.1 Beta 2 上尝试了上下文参数的解决方案,并且效果很好:

finally, i tried the solution of the context param on the latest version ICEfaces 2.1 Beta 2 and it works fine:

<context-param>
        <param-name>org.icefaces.messagePersistence</param-name>
        <param-value>false</param-value>
  </context-param>

http ://wiki.icefaces.org/display/ICE/ICEfaces+2.1.0+Beta+2+Release+Notes#ICEfaces2.1.0Beta2ReleaseNotes-下载

希望会有所帮助.

这篇关于人脸消息不会在后续请求中清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆