0

I am using JSF 2.3, when i use @managedBean, everything goes well, but when i change it to @Named, i get following error:

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-000072: Bean declaring a passivating scope must be passivation capable.  Bean:  Managed Bean [class com.eastnets.bean.User] with qualifiers [@Default @Any @Named]
    at org.jboss.weld.bean.ManagedBean.checkType(ManagedBean.java:216)
    at org.jboss.weld.bean.AbstractBean.initializeAfterBeanDiscovery(AbstractBean.java:108)
    at org.jboss.weld.bean.ManagedBean.initializeAfterBeanDiscovery(ManagedBean.java:122)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$AfterBeanDiscoveryInitializerFactory.doWork(ConcurrentBeanDeployer.java:111)
    at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$AfterBeanDiscoveryInitializerFactory.doWork(ConcurrentBeanDeployer.java:102)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    at java.base/java.lang.Thread.run(Thread.java:832)

my bean

package com.eastnets.bean;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;

@Named("user")
@SessionScoped
public class User {
    
    private String name;
    private String password;
    
    public User() {}

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

my Configuration Bean

package com.eastnets.config;

import javax.faces.annotation.FacesConfig;

/**
 * The presence of the @FacesConfig annotation on a managed bean deployed within an application enables version specific
 * features. In this case, it enables JSF CDI injection and EL resolution using CDI.
 *
 */
@FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class ConfigurationBean {
}

context.xml file

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/hello-jsf"/>

my beans.xml file is empty, but the cursor points on the first line, i don't know if there is a way to avoid that.

may faces-config.xml file

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_3.xsd"
    version="2.3">

</faces-config>

my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>Login</display-name>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>


    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>


    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>


</web-app>

my index.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <title>Hello JSF 2.3</title>

    <style>
.loginPanel {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
}

#loginId {
    margin-left: auto;
    margin-right: auto;
    width: 15em;
    margin-top: 190px;
}
</style>

</h:head>
<h:body>

    <div id="loginId">
        <h3>LOGIN :</h3>
    </div>

    <h:form>
        <p:panel styleClass="loginPanel">
            <div style="margin-top: 20px">
                <span class="ui-float-label"> <p:inputText id="float-input" value="#{user.name}" />
                    <p:outputLabel for="@previous" value="Username" />
                </span>
            </div>

            <div style="margin-top: 20px">
                <span class="ui-float-label"> <p:password id="nonFeedback" value="#{user.password}"/>
                    <p:outputLabel for="@previous" value="Password" />
                </span>
            </div>

            <p:commandButton value="Submit" id="submit" action="results"
                style="margin-right:20px; margin-top:10px" ajax="false" />

        </p:panel>
    </h:form>



</h:body>
</html>

the pom.xml file

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Login</groupId>
    <artifactId>Login</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>



    <properties>
        <jsf.version>2.3.2</jsf.version>
        <javase.version>1.8</javase.version>
        <javaee.version>8.0</javaee.version><!-- Update to Java EE 8 once available -->

        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- JSF 2.3 dependencies for Tomcat -->
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.faces</artifactId>
            <version>${jsf.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet-shaded</artifactId>
            <version>3.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>${javaee.version}</version>
            <scope>provided</scope>
        </dependency>

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

    </dependencies>






    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <configuration>
                    <warSourceDirectory>WebContent</warSourceDirectory>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Omar
  • 13
  • 3

1 Answers1

0

The bean needs to implement Serializable. Change your User class as follows:

public class User implements Serializable
Dan Nemes
  • 172
  • 1
  • 11
  • It is working, oh my god, i spent more than 2 days trying to solve this porblem. now i need to search about why this is working. – Omar Dec 05 '20 at 12:04
  • It's explained here: https://stackoverflow.com/q/2294551 – BalusC Dec 05 '20 at 12:09