CDI managed bean: Target Unreachable, identifier 'myBean' resolved to null

38 Views Asked by At

For some reason my xhtml page can not find my CDI managed bean. I have seen a lot of resources on the problem for instance (Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable), but I have still not been to solve the problem.

This is the Bean that I am injecting.

import java.io.Serializable;

import javax.faces.bean.ApplicationScoped;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;


@SessionScoped
@Named
public class MyMB implements Serializable{

    private Integer max;

private static final long serialVersionUID = 1L;


    public MyMB(){
        super();
        max = 1;
    }

    public void setMax(Integer max) {
        this.max = max; 
    }

    public Integer getMax(){
        return this.max;
    }

    public String priority(){
        return "priority";
    }
}

This is where I am injecting it.

import java.io.Serializable;
import javax.enterprise.context.SessionScoped;
import javax.inject.Inject;
import javax.inject.Named;

@Named
@SessionScoped
public class MyBean implements Serializable {

    private static final long serialVersionUID = 1L;

    String name = "myBean";

    @Inject
    private MyMB myMB;

    MyMB getMyMB(){
        return myMB;
    }
}

And here is my xhtml page.

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://xmlns.jcp.org/jsf/html">

<h:head>
    <h:outputStylesheet library="css" name="todo.css" />
    <title>bean settings</title>
</h:head>

<body>
    <h:outputText value="Edit myBean"/>
    ManagedBean is: #{myBean.name}
    <h:form>
        <h:inputText value="#{myBean.myMB.max}"
 converterMessage="Only numbers please" />
        <h:commandButton value="Speichern" type="submit" action="#{myBean.myMB.priority}" />
    </h:form>   

</body>
</html>

For some reason the xhtml page cannot seem to find the myBean class and i get this error message.

/myPage.xhtml @20,105 value="#{myBean.myMB.max}": Target Unreachable, identifier 'myBean' resolved to null

0

There are 0 best solutions below