1

I am trying to implement a sign up page on Tomcat server, but the backing bean isn't created, when I click the submit button I get the following error.

Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'registerBean' resolved to null at org.apache.el.parser.AstValue.getTarget(AstValue.java:98) at org.apache.el.parser.AstValue.getType(AstValue.java:82) at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:172) at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)

here is the RegisterBean.java

package com.please.beans;

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


@Named
@SessionScoped
public class RegisterBean implements Serializable{

    private String emailAddress="3234234";
    private String userName;
    private String password;

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void doLogin(){
        System.out.println("Test sucessful");

    }

}

Here is signup.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!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:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>
        Hello from Facelets
        <h:form>
            <h:outputText value="E-mail address" ></h:outputText>
            <h:inputText id="emailaddress" value="#{registerBean.emailAddress}" required="true"></h:inputText>
            <h:outputText value="Password"></h:outputText>
            <h:inputSecret id="password" value="#{registerBean.password}"></h:inputSecret>

            <h:outputText value="#{registerBean.emailAddress}"></h:outputText>
            <h:commandButton action="#{registerBean.doLogin()}"></h:commandButton>

        </h:form>
    </h:body>

</html>
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Salih Erikci
  • 5,076
  • 12
  • 39
  • 69
  • How **exactly** did you install CDI on Tomcat? Tomcat doesn't natively support CDI, so you'd have to install this manually. The chance is very big you made some serious mistake during manually installing CDI on Tomcat. At least, the symptoms confirms that CDI `@Named` doesn't work at all. – BalusC Jan 20 '14 at 20:07
  • In any case ... The chance is yet bigger that this question is a genuine dupe: http://stackoverflow.com/q/18995951 – BalusC Jan 20 '14 at 20:09
  • @BalusC yes it seem like a duplicate but i didn't see that question before. – Salih Erikci Jan 20 '14 at 20:13
  • 2
    Okay. Related blog: http://balusc.blogspot.com/2013/10/how-to-install-cdi-in-tomcat.html – BalusC Jan 20 '14 at 20:14

1 Answers1

-3

Change annotation like :

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="registerBean")
@SessionScoped
public class RegisterBean implements Serializable{
//Your code here
..........................
}
  • 2
    -1, I am trying to use CDI – Salih Erikci Jan 20 '14 at 20:13
  • FYI: `@ManagedBean` and friends are going to be deprecated in next Java EE version. As OP is already at JSF 2.2 (Java EE 7), he's strongly encouraged to move to CDI `@Named`. See also the blog link in the question for more detail. – BalusC Jan 20 '14 at 20:14