0

I am a beginner in developing webapplications and I'm trying to learn how to use managedbeans. I have done a working condition html form that when submitting, links me to a new page. Now I'm trying to implement managed beans to my application.

The error I get is the Target Unreachable, identifier [bean] resolved to null. I had read pretty much all the previous questions on SO on the subject, but none have helped me. Ive tried without the preconstruct, serializable and no scope defined as well as the code below, but same result The problem occurs when pressing the submitbutton in the form.

IntelliJ finds the class student with firstName and lastName, so I suspect something is wrong with my configurations.

I am using tomcat8 along with javaserver faces 2.2, java 1.8, dynamic web module 3.1 and mojarra 2.2.0 my faces-config.xml is prettymuch empty since Im using JSF 2.xx

Ive spend lots of hours on this now, and would appreciate some help, thanks in advance!

student.java

package javaee2;
import java.io.Serializable

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


@ManagedBean
@RequestScoped
public class Student implements Serializable {

public String firstName;


public Student(){

}

@PostConstruct
public void init(){
    this.firstName = "";
}

public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
}

student_form.xhtml:

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Student Registration Form</title>
    </h:head>
    <h:body>
        <h:form>
            First name: <h:inputText value="#{student.firstName}" />        
            <br/><br/>
            <h:commandButton value="Submit" action="student_response" />

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

student_response.xhtml

<!DOCTYPE html>
<html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html">
    <h:head>
    <title>Student Confirmation</title>
</h:head>
<h:body>
    The student is confirmed: #{student.firstName} #{student.lastName}

</h:body>

exception

javax.servlet.ServletException: /student_form.xhtml @14,60 value="#{student.firstName}": Target Unreachable, identifier 'student' resolved to null javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause

javax.el.PropertyNotFoundException: /student_form.xhtml @14,60 value="#{student.firstName}": Target Unreachable, identifier 'student' resolved to null com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100) com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046) javax.faces.component.UIInput.validate(UIInput.java:976) javax.faces.component.UIInput.executeValidate(UIInput.java:1249) javax.faces.component.UIInput.processValidators(UIInput.java:712) javax.faces.component.UIForm.processValidators(UIForm.java:253) javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195) com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'student' resolved to null org.apache.el.parser.AstValue.getTarget(AstValue.java:74) org.apache.el.parser.AstValue.getType(AstValue.java:58) org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:168) com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98) com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95) javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046) javax.faces.component.UIInput.validate(UIInput.java:976) javax.faces.component.UIInput.executeValidate(UIInput.java:1249) javax.faces.component.UIInput.processValidators(UIInput.java:712) javax.faces.component.UIForm.processValidators(UIForm.java:253) javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261) javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195) com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76) com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

0 Answers0