0

I have got maven project with JSF 2.1. IDE is eclipse. Server is JBoss 7.1.1. I get:

Target Unreachable, identifier 'helloBean' resolved to null: javax.el.PropertyNotFoundException: /hello.xhtml @14,42 value="#{helloBean.name}": Target Unreachable, identifier 'helloBean' resolved to null** when I click **welcome button.

The problem exists only if I have in project faces-config.xml file in WEB-INF. When I delete this file and run again, everything is OK. So, what might be wrong with this file.

Below, my ManagedBean:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.Serializable;

@ManagedBean
@SessionScoped
public class HelloBean implements Serializable {

    private static final long serialVersionUID = 1L;

    public HelloBean() {}

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void welcome() {
        System.out.println("Welcome");
    }
}

part of hello.xhtml

 <h:form>
    <h:inputText value="#{helloBean.name}"></h:inputText>
        <h:commandButton value="Welcome Me" 
        actionListener="#{helloBean.welcome}"></h:commandButton>
</h:form>

my faces-config file:

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
   xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
   version="2.1">
</faces-config>

and web.xml file:

<?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"        xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
 id="WebApp_ID" version="2.5">

   <display-name>JavaServerFaces</display-name>

   <!-- Change to "Production" when you are ready to deploy -->
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

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

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

    <!-- Map these files with JSF -->
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
</web-app>

Is it possible that empty faces-config.xml file disable annotation detection of my ManagedBean? When I delete it, everything is ok.

Emeres
  • 33
  • 1
  • 5
  • 1
    There a long story depicted [here](http://stackoverflow.com/q/30128395/1391249) which you might find interesting. As a side note : All of those URL patterns can be combined into a single `` section (element). Besides, you should not be interested in using this URL pattern `/faces/*` unless you use EOL JSF 1.x. – Tiny Aug 01 '15 at 20:17
  • This suggests that the actual JSF API being loaded during webapp runtime isn't JSF 2.1 compatible. Did you manually bundle JSF 2.0 API JAR(s) along with webapp? That Servlet 2.5 root declaration is also suspicious as it's a step backwards from what JBoss AS 7 supports. – BalusC Aug 01 '15 at 21:23
  • I forgot to add, as you're using Maven, it would be wise to list all webapp-provided dependencies specified in the pom. Just to make sure you didn't accidentally provide wrong ones along with the webapp as compared to ones already provided by the target runtime. – BalusC Aug 01 '15 at 21:43

0 Answers0