1

I'm new to JSF and can't figure out what's going on.
I keep getting this error: /index.xhtml @12,80 value="#{LoginBean.username}": Target Unreachable, identifier 'LoginBean' resolved to null

I've isolated the problem down to this...

index.xhtml

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>JSF 2.0 LoginApp</title>
</h:head>
    <h:body>
        <h2>JSF 2.0 Login App</h2><br/>
        <h:form>
            Username: <h:inputText id="username" value="#{LoginBean.username}">  //error here
            </h:inputText> <br/><br/>
            Password: <h:inputSecret id="password" value="#{LoginBean.password}">  //and error here
            </h:inputSecret> <br/><br/>
            <h:commandButton action="response.xhtml" value="Login" type="Submit"></h:commandButton>
        </h:form>


    </h:body>
</html>

response.xhtml

    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Login Response</title>
    </h:head>
    <h:body>
        <h:outputText id="result" escape="false" value="#{LoginBean.authenticate}"/>
    </h:body>
</html>

LoginBean.java

public class LoginBean {
private String username;
private String password;
}
B.B
  • 11
  • 1
  • 2

4 Answers4

2

Don“t use Managedbean anymore.

Switch to CDI instead

Add this on top of your class @RequestScoped ( from javax.enterprise.context.RequestScoped ) @Named("LoginBean")

see http://docs.oracle.com/javaee/6/tutorial/doc/gjbnr.html for further informations

urbiwanus
  • 713
  • 5
  • 21
2

You should fix your bean name in jsf EL.I think you didn't give a name to your bean.Therefore in jsf EL, your bean name must start with lower case.It is jsf default.

Change value="#{LoginBean.username}" to value="#{loginBean.username}"

mstzn
  • 2,881
  • 3
  • 25
  • 37
1

Make sure your bean has

  1. The annotation @ManagedBean (make sure to use import javax.faces.bean.ManagedBean;)!
  2. A public no-arg constructor
  3. Getters and setters for username and password
ACV
  • 9,964
  • 5
  • 76
  • 81
0

Make sure your loginBean is annotated with @ManagedBean. If your class name is LoginBean then identifier in EL becomes loginBeanas per java conventions and not LoginBean

Prasad Kharkar
  • 13,410
  • 5
  • 37
  • 56