2

I'm trying to get the simplest possible JSF example I could find working with Tomcat: The javaee-tutorial/examples/web/jsf/hello1 example from the JavaEE 7 SDK download. This is the example that the official tutorial uses to introduce you to JSF. (Full disclosure - I'm new to JSF, but not to Java or Tomcat.) All the files are straight out of the JavaEE SDK examples - of course, Oracle wants you to use Glassfish and Netbeans, not Tomcat and IntelliJ, so I'm trying to add the necessary dependencies to get it to compile and run.

So far it compiles and runs fine, but when I press the "Submit" button on the form, instead of another page that says "Hello, yournamehere!" I get an error page:

An Error Occurred:

/index.xhtml @20,43 value="#{hello.name}": Target Unreachable, identifier 'hello' resolved to null
- Stack Trace

javax.el.PropertyNotFoundException: /index.xhtml @20,43 value="#{hello.name}": Target Unreachable, identifier 'hello' resolved to null
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
    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:1258)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
    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:303)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2440)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2429)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:744)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'hello' resolved to null
    at org.apache.el.parser.AstValue.getTarget(AstValue.java:97)
    at org.apache.el.parser.AstValue.getType(AstValue.java:81)
    at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:171)
    at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
    ... 34 more
- Component Tree

<UIViewRoot id="j_id1" inView="true" locale="en_US" renderKitId="HTML_BASIC" rendered="true" transient="false" viewId="/index.xhtml">
javax_faces_location_HEAD
<ComponentResourceContainer id="javax_faces_location_HEAD" inView="true" rendered="true" transient="false">
<UIOutput id="__rf_skinning_resource" inView="true" rendered="true" transient="false"/>
</ComponentResourceContainer>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<UIOutput id="j_idt2" inView="true" rendered="true" transient="false">
<title>Facelets Hello Greeting</title>
</UIOutput>
<HtmlBody id="j_idt4" inView="true" rendered="true" transient="false">
<HtmlForm enctype="application/x-www-form-urlencoded" id="j_idt5" inView="true" prependId="true" rendered="true" submitted="true" transient="false">
<HtmlGraphicImage alt="Duke waving his hand" id="j_idt6" inView="true" ismap="false" rendered="true" transient="false" url="/hello1/javax.faces.resource/duke.waving.gif.xhtml?ln=images" value="/hello1/javax.faces.resource/duke.waving.gif.xhtml?ln=images"/>
<h2>Hello, my name is Duke. What's yours?</h2>
<HtmlInputText disabled="false" id="username" immediate="false" inView="true" localValueSet="false" maxlength="25" readonly="false" rendered="true" required="true" requiredMessage="Error: A name is required." size="-2147483648" submittedValue="yournamehere" title="My name is: " transient="false" valid="true"/>
<p/>
<HtmlCommandButton action="response" actionExpression="response" disabled="false" id="submit" immediate="false" inView="true" readonly="false" rendered="true" transient="false" type="submit" value="Submit"/>
<HtmlCommandButton disabled="false" id="reset" immediate="false" inView="true" readonly="false" rendered="true" transient="false" type="reset" value="Reset"/>
</HtmlForm>
<div class="messagecolor">
<HtmlMessages errorStyle="color: #d20005" globalOnly="false" id="j_idt10" inView="true" infoStyle="color: blue" layout="list" redisplay="true" rendered="true" showDetail="false" showSummary="true" tooltip="false" transient="false"/>
</div>
</HtmlBody>
</html>
</UIViewRoot>
- Scoped Variables

Request Parameters
Name    Value
j_idt5  j_idt5
j_idt5:submit   Submit
j_idt5:username yournamehere
View Attributes
Name    Value
None
Request Attributes
Name    Value
None
Flash Attributes
Name    Value
None
Session Attributes
Name    Value
None
Application Attributes
Name    Value
csfcff  [ ]
Mar 21, 2015 11:15:56 AM - Generated by Mojarra/Facelets

I've tried cleaning the target directory, rebuilding the project, googling this error - no luck. And this error seems very robust - nothing I do changes it.

Clearly there's a disconnect somewhere, but I have no idea what it would be, and it's hard to figure out without a working example to compare it to.

Here's the POM file as modified by me, everything else is stock, from the Oracle example:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.glassfish.javaeetutorial</groupId>
    <artifactId>hello1</artifactId>
    <version>7.0.5</version>
    <packaging>war</packaging>

    <name>${project.artifactId}</name>

    <properties>
        <javaee.api.version>7.0</javaee.api.version>
        <jsfVersion>2.2.6</jsfVersion>
        <tomcat.version>7.0.55</tomcat.version>
    </properties>

    <dependencies>
        <!-- ********************* JavaEE stuff ************************* -->

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>${javaee.api.version}</version>
            <scope>provided</scope>
        </dependency>

        <!--  ********************** JSF Dependencies ************************************* -->


        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>${jsfVersion}</version>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>${jsfVersion}</version>
        </dependency>

        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>${jsfVersion}</version>
        </dependency>

        <!-- **************************** RichFaces Dependencies ***********************  -->
        <dependency>
            <groupId>org.richfaces</groupId>
            <artifactId>richfaces</artifactId>
            <version>4.5.3.Final</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.2.Final</version>
        </dependency>

        <!--  ************************** Tomcat dependency to get web.xml stuff to resolve in Intellij -->
        <dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-catalina</artifactId>
            <version>7.0.55</version>
            <scope>provided</scope>
        </dependency>



    </dependencies>

</project>

Can anybody spot anything?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user3120173
  • 1,758
  • 7
  • 25
  • 39
  • Did you create the Hello class? – Cesar Loachamin Mar 21 '15 at 18:30
  • Yes, the Hello class, the web.xml, and the two xhtml files required by the example are all present and untouched, just as they came from the Java EE SDK. It is my understanding, reading the tutorial, that the example is supposed to work without modification. The only thing I am doing differently is running it on Tomcat (not a full EE server) instead of Glassfish. The only reason I didn't put all the source into the example is that it would have made the question very, very, very long. – user3120173 Mar 21 '15 at 18:35
  • That is the problem you have to use glassfish for this example it use CDI and it requires an application server – Cesar Loachamin Mar 21 '15 at 18:37
  • Have you specified any bean class. A normal class in `JSF` won't be able to communicate with facelets. You must specify a class as bean. Check this link http://stackoverflow.com/questions/746047/jsf-backing-bean-structure-best-practices – Vighanesh Gursale Mar 21 '15 at 19:00
  • 1
    ["*There is nothing named JEE! Never use that name! The correct short name is "Java EE"*"](https://java.net/projects/javaee-spec/pages/JEE). – Tiny Mar 22 '15 at 02:43
  • Tomcat is not a Java EE container. It's a barebones JSP/Servlet container. – BalusC Mar 23 '15 at 07:51

1 Answers1

1

If you want to use the example in Tomcat you have two options add CDI to tomcat you could check this link that also describe the problem you're facing or you can use the JSF ManagedBeans instead of CDI in this way

import javax.faces.bean.ManagedBean
import javax.faces.bean.RequestScoped
@ManagedBean
@RequestScoped
public class Hello {

    private String name;

    public Hello() {
    }

    public String getName() {
        return name;
    }

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

Check the imports they are different packages from the example

Cesar Loachamin
  • 2,740
  • 4
  • 25
  • 33
  • 1
    Thank you, yes the problem turned out to be fixed by pulling out all the JEE packages and adding the javax.faces API and the Mojarra Faces implementation: javax.faces javax.faces-api 2.2 org.glassfish javax.faces 2.2.9 – user3120173 Mar 21 '15 at 19:55