20

I have a problem with JSF 2.2 and CDI, my managerbean is not solved and this error appear

"value="#{userBean.user.name}": Target Unreachable, identifier 'userBean' resolved to null"

This is my manager bean.

@ManagedBean
@RequestScoped
public class UserBean implements Serializable {
    private User user;

    public void setUser(user) {
        this.user = user;
    }
    ...
}

My view is:

<h:form id="login-form">
    <h:outputText value="User"/>
    <h:inputText value="#{userBean.user.name}" id="username"/>

    <h:outputText value="Senha"/>
    <h:inputSecret value="#{userBean.user.password}" id="pasword"/>

    <h:commandButton id="button" value="Login" action="#{userBean.login}"/>

    <h:messages />
</h:form>
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
SaXeTz
  • 500
  • 1
  • 3
  • 14
  • 1
    Do you possibly have `faces-config.xml`? – PM 77-1 Dec 10 '13 at 22:36
  • 2
    What packages are you importing those annotations from and on what app server are you running your app? – kolossus Dec 10 '13 at 22:38
  • *Make sure that you've properly performed a full clean, rebuild, redeploy* ... this was the step that I was omitting from BalusC's post and it fixed the problem. – ROMANIA_engineer Jan 05 '16 at 15:26
  • Having two different java versions installed can also cause this error. I faced the same issue and it got solved by uninstalling one of it. – Hetal Rachh Apr 09 '19 at 18:18
  • For me this error occurred because of the presence of 1 jar. It took removing/re-adding every jar to the class line by line to identify it – nettie May 13 '21 at 13:04
  • You should add below line to faces-config.xml file. org.springframework.web.jsf.el.SpringBeanFacesELResolver – salihgungor Sep 16 '22 at 11:53

3 Answers3

24

I want to share my experience with this Exception. My JSF 2.2 application worked fine with WildFly 8.0, but one time, when I started server, i got this "Target Unreacheable" exception. Actually, there was no problem with JSF annotations or tags.

Only thing I had to do was cleaning the project. After this operation, my app is working fine again.

I hope this will help someone!

akelec
  • 3,797
  • 3
  • 41
  • 39
  • right click on server > clean didn't work for me. I dunno if it what made it work but I clicked restart on the project (not the server). – Ced Apr 10 '16 at 07:30
  • 1
    It happened to me a few times, sometimes cleaning the project solved it and sometimes restarting glassfish worked – Fred Nov 06 '17 at 06:35
  • Had the same issue, for me restarting and cleaning didn't work. But after restarting Eclipse everything went back to normal – TomasZ. Dec 06 '17 at 06:44
  • Mine was the same issue, except I had to stop the server, clean the server and restart it. – Hemmels Jan 26 '18 at 19:58
  • I can confirm that if this exception suddenly pops up, while your project was working the day before without a hitch, it could be a dev-machine's memory shortage. This especially can happen if you are repeatedly closing down your computer into suspend or hibernation mode and don't restart or power off for a long time (like multiple weeks). A restart with power off at the best should help here. The same situation is valid if you are working on stateful VMs. And the types of OSes and IDEs are playing a role there too – woodz Mar 06 '20 at 10:21
  • What do you mean by "cleaning the project"? – Jasper de Vries May 03 '23 at 13:01
15

I solved this problem.

My Java version was the 1.6 and I found that was using 1.7 with CDI however after that I changed the Java version to 1.7 and import the package javax.faces.bean.ManagedBean and everything worked.

Right click on Project > Properties > Java Compiler > Make Sure the Java version installed in class path is same as the java compiler. Thanks @PM77-1


Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
SaXeTz
  • 500
  • 1
  • 3
  • 14
14
  1. You need

    @ManagedBean(name="userBean")

  2. Make sure you have getUser() method.

  3. Type of setUser() method should be void.

  4. Make sure that User class has proper setters and getters as well.

PM 77-1
  • 12,933
  • 21
  • 68
  • 111