0

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

Community
  • 1
  • 1
Sebelulu
  • 11
  • 1
  • 1
    You still haven't explicitly excluded everything from the troubleshooter which you found. Please do so, or this question remains unanswerable because no one in the world can reproduce your problem in a clean project based on the information provided so far, and every possible cause is already for long mentioned in that troubleshooter. – BalusC Jan 22 '17 at 15:55
  • So it was a problem with my configuration of the project. Instead of a problem in the code retrieving the bean. I had not used Weld. – Sebelulu Jan 22 '17 at 23:41

0 Answers0