Target Unreachable, identifier resolved to null in JSF 2.2 [duplicate]
Asked Answered
D

3

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>
Dopey answered 10/12, 2013 at 20:32 Comment(6)
Do you possibly have faces-config.xml?Doomsday
What packages are you importing those annotations from and on what app server are you running your app?Cysticercus
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.Gattis
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.Dockage
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 itPhone
You should add below line to faces-config.xml file. <application> <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver </el-resolver> </application>Heir
D
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


Dopey answered 12/12, 2013 at 17:17 Comment(0)
A
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!

Amble answered 14/12, 2014 at 17:45 Comment(6)
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).Overliberal
It happened to me a few times, sometimes cleaning the project solved it and sometimes restarting glassfish workedPamalapamela
Had the same issue, for me restarting and cleaning didn't work. But after restarting Eclipse everything went back to normalAgitate
Mine was the same issue, except I had to stop the server, clean the server and restart it.Hypertension
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 tooTyus
What do you mean by "cleaning the project"?Zipangu
D
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


Dopey answered 12/12, 2013 at 17:17 Comment(0)
D
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.

Doomsday answered 10/12, 2013 at 20:43 Comment(6)
By default the bean name will be userBean... don't need to set it.Bohr
@AlexandreLavoie - Can you please refer me to official documentation that states this fact?Doomsday
docs.oracle.com/javaee/6/api/javax/faces/bean/ManagedBean.html second paragraphBohr
Yes, The type of setUser is void, sorry I was wrong when I wrote the text. When I put '(name="userBean")' is showing to me this warning.Dopey
Make sure that you're importing this annotation from javax.faces.bean package.Doomsday
To varify this, you can always check your .war-File in /WEB-INF/classes/* if your class exists or not.Witchhunt

© 2022 - 2024 — McMap. All rights reserved.