3

Preface: I have thoroughly looked at about 10 different related stackoverflow articles such as the ones below, none of which solved my question. So I am presenting the complete code to see if anyone knows what might be wrong with my project. Please do not mark this as duplicate as I have already did an exhaustive research on other articles like this.

Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable

Target Unreachable, identifier 'user' resolved to null

JSF Target unreachable identifier resolved to null

Target Unreachable, identifier resolved to null in JSF 2.2

Java EE 6: Target Unreachable, identifier 'helloBean' resolved to null


My exact error I get when I try to run the below JSF application (which is a very simple web app) is

javax.el.PropertyNotFoundException: /index.xhtml @15,45 value="#{user.name}": Target Unreachable, identifier 'user' resolved to null
    at com.sun.jsf-impl@2.3.9.SP02//com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:64) ...

I do not know how to solve this problem, even after consulting a ton of other stackoverflow articles. I have concluded the following:

1) if there is an error in the code, then I do not know what is wrong so please point it out, thanks!

2) if the code looks fine to you, can you please rebuild it on your own machine and see if it can deploy properly? I have a feeling it might not have to do with the code since I have literally tried so many different variations.

Tools used: I am using Eclipse, Java 11, JSF 2.2, Servlet 3.1, Wildfly 17

UserBean.java

package com.corejsf;

import java.io.Serializable;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;

@Named("user")
@SessionScoped
public class UserBean implements Serializable {
    private String name;
    private String password;

    public String getName() {
        return name;
    }

    public void setName(String newValue) {
        name = newValue;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String newValue) {
        password = newValue;
    }
}

index.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:h="http://java.sun.com/jsf/html">
<h:head>
    <title>Welcome</title>
</h:head>
<h:body>
    <h:form>
        <h3>Please enter your name and password.</h3>
        <table>
            <tr>
                <td>Name:</td>
                <td><h:inputText value="#{user.name}" /></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><h:inputSecret value="#{user.password}" /></td>
            </tr>
        </table>
        <p>
            <h:commandButton value="Login" action="welcome" />
        </p>
    </h:form>
</h:body>
</html>

welcome.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:h="http://java.sun.com/jsf/html">
<h:head>
    <title>Welcome</title>
</h:head>
<h:body>
    <h3>Welcome to JavaServer Faces, #{user.name}!</h3>
</h:body>
</html>

web.xml

<?xml version="1.0"?>
<web-app version="3.1"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <display-name>login</display-name>
    <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>/faces/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
</web-app>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>

<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">

</faces-config>

EDIT: On the IDE, my Package Explorer looks like this : folder structure

However, Web Projects shows this (notice that is no file under the 'Beans' folder or 'classes' folder. Not sure if this is supposed to happen as I am new to JSF). If this is normal, please ignore. I just wanted to include as much information as I caN

Web Projects

Sekai
  • 31
  • 3
  • It should work, but you can try with xml based configurations. – notescrew Sep 05 '19 at 18:11
  • that does not answer my question in any way what so ever. – Sekai Sep 05 '19 at 18:14
  • Wildfly 17 is jsf 2.3 (.9SP02) as your error shows... on which page do you get the error? Already when loading the index.xhtml? What if you replace the content of the welcome file to the index file? Same error? Is the java file actually deployed? I can try tomorrow... – Kukeltje Sep 05 '19 at 21:07
  • oh and change the `h:` namespace declarationsn the xhtml files to the jsf 2.2+ ones. And did you try the `@FacesConfig` fix? – Kukeltje Sep 05 '19 at 21:34
  • And change the faces-config.xml to 2.3 – Kukeltje Sep 05 '19 at 21:40
  • error occurs when I click the commandButton in index.xhtml – Sekai Sep 05 '19 at 22:39
  • still not working, please give it a try tomorrow @Kukeltje , thank you! – Sekai Sep 06 '19 at 01:26
  • I will, but at least update your question with corrected things from the earlier comment so I can use that – Kukeltje Sep 06 '19 at 06:04
  • Are you using Maven and having a pom.xml? – Selaron Sep 06 '19 at 06:05
  • changing faces-config.xml to 2.3 gives an error when I start my wildfly server. And I believe I am already using the correct h: namespace declarations for jsf 2.2. Please correct me if I am wrong on this, though. – Sekai Sep 06 '19 at 07:00
  • Not using maven so no pom.xml file – Sekai Sep 06 '19 at 07:00
  • Added screenshots of Package Explorer and Web Projects. Please take a look and see if those are correct. – Sekai Sep 06 '19 at 07:09
  • https://stackoverflow.com/questions/31068678/which-xml-namespace-to-use-with-jsf-2-2-and-up and if using 2.3 in the faces config gives you an error when you actually use 2.3, fix THAT... by asking a question about it. I'm not going to investigate with 2.2 in the faces-config.xml, sorry. – Kukeltje Sep 06 '19 at 07:22
  • `WEB-INF/classes` is an output folder, if it is empty, your java file is not compiled and the error you get is very normal. See **_1c_** in https://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable. If the class is not compiled, this is not a jsf thing but a plain java web development thing your javaSource folder does not look to be a real source folder for eclipse. So fix that first (and then the jsf 2.3 thing) – Kukeltje Sep 06 '19 at 07:25
  • Yes this matches 1c. Take a step back and learn how to create, develop and build a normal WAR project in Eclipse. Moreover the location of your UserBean.java file in your screenshot does not at all match the declared `package` in the class' source code. This is honestly definitely not a JSF/CDI problem but basic Java. – BalusC Sep 06 '19 at 12:01
  • @Kukeltje I just re-read over 1c in that link, but I still do not know how to make 'javaSource folder a real source folder for Eclipse'. – Sekai Sep 07 '19 at 01:42
  • @BalusC I made the UserBean.java file match the declared package but it is still not showing up in WEB-INF/classes, probably because of the reason I mentioned in the previous comment. – Sekai Sep 07 '19 at 01:44
  • Then take a step back and read an eclipse java 101 tutorial. This is not the area I'm providing suppprt for. – Kukeltje Sep 07 '19 at 06:21
  • I managed to get it to work, but there is still no class file under WEB-INF folder. However, the UserBean class is now in the Beans folder under Web Projects view (where as before, it wasn't there). Although I can run my web app now, because there is no class under WEB-INF folder (I can create the WAR and there is a .class file in that path, but on Web Projects view on Eclipse it does not show (see screenshot above)), I am still worried I am doing something wrong... – Sekai Sep 07 '19 at 07:31

0 Answers0