0

I've got a strange issue concerning the usage of an el-tag in JSF. I have an nearly empty project with the following dependencies:

<dependency>
        <groupId>javax.el</groupId>
        <artifactId>el-api</artifactId>
        <version>2.2</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish.web</groupId>
        <artifactId>el-impl</artifactId>
        <version>2.2</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-api</artifactId>
        <version>2.2.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.faces</groupId>
        <artifactId>jsf-impl</artifactId>
        <version>2.2.4</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>4.0</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.themes</groupId>
        <artifactId>cupertino</artifactId>
        <version>1.0.10</version>
    </dependency>
    <dependency>
        <groupId>org.primefaces.themes</groupId>
        <artifactId>all-themes</artifactId>
        <version>1.0.10</version>
    </dependency>

And I have an bean, which starts like this:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ApplicationScoped;

@ManagedBean(name = "requester")
@ApplicationScoped
public class UserBean implements Serializable {
   public String getRequestIdentificator() {
        return requestIdentificator;
   }

    public void setRequestIdentificator(String requestIdentificator) {
        this.requestIdentificator = requestIdentificator;
    }

and web.xml looks like this:

<web-app version="3.0"
         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-app_3_0.xsd"
         id="DAS_ID">

    <display-name>DAS</display-name>

    <context-param>
        <param-name>org.apache.myfaces.EXPRESSION_FACTORY</param-name>
        <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.expressionFactory</param-name>
        <param-value>com.sun.el.ExpressionFactoryImpl</param-value>
    </context-param>
    <context-param>
        <description>Parameter required by Mojarra 2.0</description>
        <param-name>com.sun.faces.allowTextChildren</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <description>
            Tell the runtime where we are in the project development
            lifecycle.  Valid values are: 
            Development, UnitTest, SystemTest, or Production.
            The runtime will display helpful hints to correct common mistakes
            when the value is Development.
        </description>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>

    <!-- 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>/faces/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>faces/main.xhtml</welcome-file>
    </welcome-file-list>

</web-app>

Unfortunately, everytime, something like <p:commandButton value="Request" action="#{requester.requestData}" /> is called, this results in

SEVERE: javax.el.PropertyNotFoundException: /main.xhtml @19,100 value="#{requester.requestIdentificator}": Target Unreachable, identifier 'requester'
resolved to null

I already searched for errors, the common errors are e.g. summarized here: Target Unreachable, identifier resolved to null, but none of this applies. Furthermore, NetBeans is able to use code-completion for everything I am doing (I also tried it with other things than requestIdentificator) - so it seems like code is written fully correct. The Bean seams never to be initialized (so the logging in the constructor is not called), but according to e.g. https://stackoverflow.com/a/11013290/2096209, is is not necessary to register the Bean in faces-config in JSF 2.x (I am using 2.1), so that can not be the problem.

I am running everything with mvn tomcat7:run. Has anybody an hint how to solve this?

Community
  • 1
  • 1
David Georg Reichelt
  • 963
  • 1
  • 15
  • 36
  • Looks like your class `UserBean` doesn't have a getter/setter for this `requestIdentificator` property. Check your managed bean definition. – Luiggi Mendoza Feb 05 '14 at 16:37
  • Just to note, this problem is not related to maven nor to your web.xml file at all... – Luiggi Mendoza Feb 05 '14 at 16:39
  • If got both getter and setter for requestIdentififactor. Thanks for the hint, I'll add them to the quest. I have no clue, where the problem is, so I posted everything what I assume could have a relation to the problem. – David Georg Reichelt Feb 05 '14 at 16:44

2 Answers2

0

I Often have this same problem using the javax.faces.bean package. Try importing

import javax.enterprise.context.ApplicationScoped;

instead of

import javax.faces.bean.ApplicationScoped;

And instead of the @ManagedBean annotation use @Named

import javax.inject.Named;
import javax.enterprise.context.ApplicationScoped;

@Named("requester")
@ApplicationScoped
public class UserBean implements Serializable {

Then build and redeploy. See if that helps

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
0

The problem was that I tried running it with mvn tomcat7:run. If I copy the war into a normal tomcat7-instance, it works, and as well, if I run it with mvn tomcat7:run-war. Seems to be an maven-tomcat-plugin bug.

David Georg Reichelt
  • 963
  • 1
  • 15
  • 36