Reputation: 1788
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?
Upvotes: 2
Views: 573
Reputation: 2738
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
Upvotes: 1