0

如何更新 @ManagedBean(已弃用)以更新 CDI 中的 @Name?我正在使用 Java 11,Maven

已弃用,但运行良好。

import javax.faces.bean.ManagedBean;

@ManagedBean 
public class EstadoBean {   
    public void salvar() {      
        System.out.println("Programação Web com Java");
    }
}

我已将其更改为:

import java.io.Serializable;

import javax.inject.Named;

@Named
public class EstadoBeanNew implements Serializable {        
    
    public void salvar() {
        
        System.out.println("Programação Web com Java");
    }
}

我的 pom.xml

<dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.6</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.6</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>

estados.xhtml

<h:panelGrid columns="2"> 
    <p:commandButton value="SALVAR"  actionListener="#{estadoBeanNew.salvar()}"  />
                    
    <p:commandButton value="FECHAR" oncomplete="PF('dlgNovoEstados').hide();"   />
</h:panelGrid>  

estadosBeanNew 控制台:

警告:/pages/estados.xhtml @52,84 actionListener="#{estadoBeanNew.salvar()}":目标无法到达,标识符 [estadoBeanNew] 解析为空 javax.el.PropertyNotFoundException:/pages/estados.xhtml @52, 84 actionListener="#{estadoBeanNew.salvar()}":目标无法到达,标识符 [estadoBeanNew] 在 com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:91) 处解析为 null

4

0 回答 0