4

I have a simple jsf app with one Bean.

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");
        }
    }

according to this answer and conversation down this post and also OmniFaces documentation OmniFaces ViewScoped bean should invoke @PreDestroy function when I navigate away by GET, or close the browser tab/window but nothings happens until session destroy.

I'm using Wildfly 15 as Application Server and i can see activeViewMaps in sessions. Yoy can see sessions content here . It's something like this :

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}}

I opened multiple windows an closed them but non of them destroyed until session destroy(30 minutes later). What's wrong? did i forget anything?

this is my 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>
armin momeni
  • 181
  • 2
  • 10
  • I have the same problem, I can't get the method annotated with `@preDestroy` of an OmniFaces (version 2.7.18) `ViewScoped` bean being called when closing the browser/tab or even when navigatiing away from the view/page. – scholt Oct 28 '22 at 13:44

0 Answers0