关闭选项卡/窗口后,OmniFaces不破坏ViewScoped bean

时间:2019-03-06 04:37:35

标签: jsf omnifaces

我有一个带有一个Bean的简单jsf应用程序。

import org.omnifaces.cdi.ViewScoped;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Named;
import java.io.Serializable;

    @Named
    @ViewScoped
    public class IndexMg implements Serializable {
        List list;

        @PostConstruct
        public void init() {
            list = new ArrayList();
            list.add("as");
            list.add("dsu");
        }

        @PreDestroy()
        public void end() {
            System.out.println("predestroy called");
        }
    }

根据this的答案和在此post下的对话以及OmniFaces documentation,当我通过GET离开或关闭浏览器标签/窗口时,OmniFaces ViewScoped bean应该调用@PreDestroy函数。但是,直到会话销毁为止,什么也不会发生。

我将Wildfly 15用作Application Server,并且可以在会话中看到activeViewMaps。 Yoy可以看到会话内容here。 就像这样:

com.sun.faces.application.view.activeViewMaps   {1d31c745-c202-4256-a2c6-60035bfdd8e7={org.omnifaces.cdi.viewscope.ViewScopeStorageInSession=b557d2aa-ba35-4ff2-9f4e-3cc4ac312c9a}, ca02df9d-be65-4a75-a399-3df9eabbcfd3={org.omnifaces.cdi.viewscope.ViewScopeStorageInSession=aaef6a5a-d385-4e33-a990-200f94b67583}}

我打开了多个窗口,然后关闭了它们,但是没有一个被销毁,直到会话销毁为止(30分钟后)。怎么了?我忘记了什么吗?

这是我的pom

 <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
 </properties>

 <dependencies>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>2.3.4</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/javax.enterprise/cdi-api -->
        <dependency>
            <groupId>javax.enterprise</groupId>
            <artifactId>cdi-api</artifactId>
            <version>2.0.SP1</version>
            <scope>provided</scope>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.omnifaces/omnifaces -->
        <dependency>
            <groupId>org.omnifaces</groupId>
            <artifactId>omnifaces</artifactId>
            <version>3.2</version>
        </dependency>

  </dependencies>

0 个答案:

没有答案