0

i'm new with jsf and when i checked my code i'm always getting this exception when i opened the browser:

 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/SampleApplication] threw exception [/login.xhtml @11,69 value="#{nameWrapper.name}": Target Unreachable, identifier 'nameWrapper' resolved to null] with root cause
javax.el.PropertyNotFoundException: Target Unreachable, identifier 'nameWrapper' 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)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:95)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
    at javax.faces.component.UIInput.validate(UIInput.java:976)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
    at javax.faces.component.UIInput.processValidators(UIInput.java:712)
    at javax.faces.component.UIForm.processValidators(UIForm.java:253)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
    at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

This is my Code:

<h:form>
    Name:
    <h:inputText id="text1" value="#{nameWrapper.name}" />
    <br />
    Address:
    <h:inputText id="text2" value="#{nameWrapper.address}" />
    <br />
    Zip:
    <h:inputText id="text3" value="#{nameWrapper.zip}" />
    <br />
    <h:commandButton id="submit" value="Submit" action="PageTwo" />
</h:form>

and:

Your password is <h:outputText id="outtext" value="#{nameWrapper.outtext}" />!

and:

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

    @ManagedBean
    @SessionScoped
    public class NameWrapper {

        private String name;
        private String address;
        private String zip;
        @SuppressWarnings("unused")
        private String outtext;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public String getZip() {
            return zip;
        }

        public void setZip(String zip) {
            this.zip = zip;
        }

        public String getOuttext() {
            return name + zip + address;
        }

        public void setOuttext(String outtext) {
            this.outtext = outtext;
        }

    }

The code is from a tutorial, and i didn't figure out what i did wrong, I followed by all the answers about this exception, and i still didn't succeed to solved it thanks!

Zoltanik
  • 175
  • 14

1 Answers1

0

You must use JSF Standard tags(h:head, h:body), which I give an example below, and also implements Serializable in ManagedBean.

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:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>Test</title>
    </h:head>
    <h:body>
        <h:form>
            Name:
            <h:inputText id="text1" value="#{nameWrapper.name}" />
            <br />
            Address:
            <h:inputText id="text2" value="#{nameWrapper.address}" />
            <br />
            Zip:
            <h:inputText id="text3" value="#{nameWrapper.zip}" />
            <br />
            <h:commandButton id="submit" value="Submit" action="PageTwo" />
        </h:form>
    </h:body>
</html>

ManagedBean

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "nameWrapper")
@SessionScoped
public class NameWrapper implements Serializable{

    private String name;
    private String address;
    private String zip;
    @SuppressWarnings("unused")
    private String outtext;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String getOuttext() {
        return name + zip + address;
    }

    public void setOuttext(String outtext) {
        this.outtext = outtext;
    }

}

XHTML of PageTwo

<?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:f="http://java.sun.com/jsf/core"      
      xmlns:h="http://java.sun.com/jsf/html">

    <h:head>
        <title>PageTwo</title>
    </h:head>
    <h:body>
        PageTwo
    </h:body>
</html>
wittakarn
  • 3,074
  • 1
  • 16
  • 30