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 :
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