0

I am building a small hello world JSF application.

My index.xhtml is as follows

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
<body>
    Hello user.
    <h:form>
        <h:inputText value="#{test.value}"></h:inputText>
        <h:commandButton value="Enter" action="welcome"></h:commandButton>
    </h:form>
</body>
</html>

My welcome.xhtml is as follows

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html">
<body>
    <h2>Welcome #{test.value}</h2>
</body>
</html>

My managed bean is as follows

package com.test.testclass;

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


@ManagedBean
@SessionScoped
public class Test {
    private String value;


    public String getValue() {
        return value;
    }


    public void setValue(String value) {
        this.value = value;
    }
}

My web.xml is as follows

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        id="WebApp_ID" version="3.0">

        <display-name>Test Project</display-name>

        <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
        </context-param>

        <!-- Welcome page -->
        <welcome-file-list>
            <welcome-file>index.xhtml</welcome-file>
        </welcome-file-list>

        <!-- Faces Servlet -->
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>
    </web-app>

My gradle build file is as follows

buildscript {
    // Repositories for libraries needed for building:
    repositories {
        mavenCentral()
        jcenter()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
}

plugins {
    id 'war'
}

war {
    webInf {
        from "WebContent/WEB-INF"
    }
    from("WebContent") {
        include "index.xhtml"
    }
    outputs.upToDateWhen {
        false
    }
}

repositories {
    mavenCentral()
    maven {
        url "http://download.java.net/maven/2/"
        url "http://repository.primefaces.org/"
    }
}

dependencies {
    def jsfApi = "javax.faces:javax.faces-api:2.2"
    def atmosphereRuntime = "org.atmosphere:atmosphere-runtime:2.4.9"

    compile \
        jsfApi,
        atmosphereRuntime

    providedCompile \
        "javax:javaee-api:7.0",
        "javax.servlet:javax.servlet-api:3.1.0", 
        "org.glassfish:javax.json:1.+"
}

task deploy(type: Copy) {
    description "Deploys the test application."
    from war.outputs
    into System.env.DEPLOY_DIR
    outputs.upToDateWhen { false }
}

I am getting the following error when I enter a string in the index page and hit enter

HTTP Status 500 - Internal Server Error
type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: /index.xhtml @9,38 value="#{test.value}": Target Unreachable, identifier 'test' resolved to null
root cause

javax.el.PropertyNotFoundException: /index.xhtml @9,38 value="#{test.value}": Target Unreachable, identifier 'test' resolved to null
root cause

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'test' resolved to null
note The full stack traces of the exception and its root causes are available in the "" logs.

""

The backend bean is set to null somehow. What am I doing wrong. Please help.

  • Out of curiosity... Did you in no way when using a search engine found any of the duplicates that are all duplicated by the same Q that yours is a duplicate of? – Kukeltje Jan 11 '18 at 16:50
  • OH and please switch to using CDI managed beans instead of JSF managed ones... And JSF-2.2+ namespace declarations in the xhtml files – Kukeltje Jan 11 '18 at 16:51

0 Answers0