0

I am trying to make a simple JSF projects but getting errors along the way... I updated my project as a maven project but still it does not work.

    <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 https://maven.apache.org/xsd/maven- 
   4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>BeatifulThingsWebapp</groupId>
   <artifactId>BeatifulThingsWebapp</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>war</packaging>
   <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <release>16</release>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.2.3</version>
      </plugin>
    </plugins>
   </build>
   <dependencies>
    <!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-impl -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.20</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.faces/jsf-api -->
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.20</version>
    </dependency>
   </dependencies>
   <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
   </properties>
   </project>

this is my index.xhtml

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets">

    <body>
    <h1>Please fill out the form</h1>
    
    <h:form>
    Tell me about something nice:
    <h:inputText value="#{bt.thingTitle}"/>
    
    Now describe it:
    <h:inputText value="#{bt.thingDescription}"/>
    
    Rate this item:
    <h:inputText value="#{bt.rating}"/>
    
    <h:commandButton action="#{controller.onSubmitEdit()}" value="OK"/>
    
    </h:form>
    </body>
    </html>

java classes

    package beans;

    import java.io.Serializable;

    import javax.faces.bean.ManagedBean;
    import javax.faces.view.ViewScoped;

    @ManagedBean(name="bt")
    @ViewScoped
    public class BeautifulThing implements Serializable{
    
    int id;
    String thingTitle;
    String thingDescription;
    int rating;
    
    //ManagedBean has to have a non argument constructor
    

    public BeautifulThing(int id, String thingTitle, String thingDescription, int rating) {
        super();
        this.id = id;
        this.thingTitle = thingTitle;
        this.thingDescription = thingDescription;
        this.rating = rating;
    }
    
    public BeautifulThing() {
        
    }

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getThingTitle() {
        return thingTitle;
    }
    public void setThingTitle(String thingTitle) {
        this.thingTitle = thingTitle;
    }
    public String getThingDescription() {
        return thingDescription;
    }
    public void setThingDescription(String thingDescription) {
        this.thingDescription = thingDescription;
    }
    public int getRating() {
        return rating;
    }
    public void setRating(int rating) {
        this.rating = rating;
    }

    @Override
    public String toString() {
        return "BeautifulThing [id=" + id + ", thingTitle=" + thingTitle + ", rating=" + 
    rating + "]";
        }       
    }
--------------------
    package controllers;

    import java.io.Serializable;

    import javax.faces.bean.ManagedBean;

    @ManagedBean(name="controller")
    public class FormController implements Serializable{
    
    //ManagedBean has to have a non argument constructor
    

    public void onSubmitEdit() {
        //when the user clicks on the submit button
        System.out.println("You clicked the OK button");
    }

    public FormController() {
        super();
        // TODO Auto-generated constructor stub
        }
    }
the error I am getting:
HTTP Status 500 – Internal Server Error

--------------------------------------------------------------------------------

Type Exception Report

Message /index.xhtml @13,41 value="#{bt.thingTitle}": Target Unreachable, identifier [bt] 
resolved to null

Description The server encountered an unexpected condition that prevented it from 
fulfilling 
the request.

Exception

javax.servlet.ServletException: /index.xhtml @13,41 value="#{bt.thingTitle}": Target 
Unreachable, identifier [bt] resolved to null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:671)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

javax.el.PropertyNotFoundException: /index.xhtml @13,41 value="#{bt.thingTitle}": Target 
Unreachable, identifier [bt] resolved to null
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInpu 
tRenderer.java:95)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1067)
javax.faces.component.UIInput.validate(UIInput.java:981)
javax.faces.component.UIInput.executeValidate(UIInput.java:1270)
javax.faces.component.UIInput.processValidators(UIInput.java:714)
javax.faces.component.UIForm.processValidators(UIForm.java:253)
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:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Root Cause

javax.el.PropertyNotFoundException: Target Unreachable, identifier [bt] resolved to null
org.apache.el.parser.AstValue.getTarget(AstValue.java:73)
org.apache.el.parser.AstValue.getType(AstValue.java:57)
org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:173)
com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInpu 
tRenderer.java:95)
javax.faces.component.UIInput.getConvertedValue(UIInput.java:1067)
javax.faces.component.UIInput.validate(UIInput.java:981)
javax.faces.component.UIInput.executeValidate(UIInput.java:1270)
javax.faces.component.UIInput.processValidators(UIInput.java:714)
javax.faces.component.UIForm.processValidators(UIForm.java:253)
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:658)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
Note The full stack trace of the root cause is available in the server logs.


--------------------------------------------------------------------------------

Apache Tomcat/9.0.50 
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102

1 Answers1

0

Your JSF container dont create your BeautifulThing bean and therefore jsf servler dont find it.

Try change @MangedBean("bt") to @Named("bt") or delete constructor with arguments. (And totaly delete super(); because your bean don't extend any other object).

If no one from this will be work, look to logs of your application server from start or deploy war.

Cheatr01
  • 51
  • 5