javax.el.PropertyNotFoundException:Target Unreachable,Identifier' beanName'找不到

时间:2016-04-01 13:12:22

标签: jsf tomcat7 ubuntu-14.04 jsf-2.2 propertynotfoundexception

所以,我尝试使用Ubuntu Server 14.04和Apache Tomcat 7设置Web服务器,但是当我部署webapp时,每当我尝试调用bean时,都会出现以下错误:

javax.el.PropertyNotFoundException: /usuario/login.xhtml @18,83 value="#{usuarioBean.obj.email}": Target Unreachable, identifier 'usuarioBean' resolved to null
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:144)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:171)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1045)
at javax.faces.component.UIInput.validate(UIInput.java:975)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1261)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'usuarioBean' resolved to null
at org.apache.el.parser.AstValue.getTarget(AstValue.java:97)
at org.apache.el.parser.AstValue.getType(AstValue.java:81)
at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:171)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)

这是我的login.xhtml代码:



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Login</title>
    </h:head>
    <h:body>
        <h:form>
            <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />

            <table>
                <tr>
                    <td><h:outputLabel for="login" value="E-mail:" /></td>
                    <td><p:inputText id="name" value="#{usuarioBean.obj.email}" /></td>
                </tr>
                <tr>
                    <td><h:outputLabel for="senha" value="Senha:" /></td>
                    <td><p:password id="senha" value="#{usuarioBean.obj.senha}" /></td>
                </tr>
                <tr>
                    <td><p:commandButton id="entrar" value="Entrar" action="#{usuarioBean.logar()}" ajax="false"/> </td>      
                    <td><p:commandButton id="novo" value="Novo" action="#{usuarioBean.criarNovo()}" ajax="false"/> </td>      
                </tr>
            </table>

        </h:form>
    </h:body>
</html>
&#13;
&#13;
&#13;

这是我的UsusarioBean类声明:

@ManagedBean ( name = "usuarioBean" )
@RequestScoped
@Data
public class UsuarioBean extends AbstractBean<Usuario, UsuarioDAO>

@Data注释来自Lombok库。

面-config.xml中

&#13;
&#13;
<?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_2.xsd"
  version="2.2">
  <navigation-rule>
    <from-view-id>/usuario/login.xhtml</from-view-id>
    <navigation-case>
      <from-outcome>escolheIgreja</from-outcome>
      <to-view-id>/igreja/setaIgrejaAtiva.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
      <from-outcome>sucesso</from-outcome>
      <to-view-id>logado.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
      <from-outcome>erro</from-outcome>
      <to-view-id>/usuario/login.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
      <from-outcome>novoUsuario</from-outcome>
      <to-view-id>/usuario/novo.xhtml</to-view-id>
    </navigation-case>
  </navigation-rule>      
  <navigation-rule>
    <from-view-id>/usuario/novo.xhtml</from-view-id>
    <navigation-case>
      <from-outcome>erro</from-outcome>
      <to-view-id>/usuario/novo.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
      <from-outcome>sucesso</from-outcome>
      <to-view-id>/index.xhtml</to-view-id>
    </navigation-case>
  </navigation-rule>      
  <navigation-rule>
    <from-view-id>/igreja/setaIgrejaAtiva.xhtml</from-view-id>
    <navigation-case>
      <from-outcome>sucesso</from-outcome>
      <to-view-id>/logado.xhtml</to-view-id>
    </navigation-case>
  </navigation-rule>
</faces-config>
&#13;
&#13;
&#13;

的pom.xml

&#13;
&#13;
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>br.com.koinonia</groupId>
    <artifactId>IgrejaHabil</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>IgrejaHabil</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>javax.servlet.jsp.jstl</groupId>
            <artifactId>javax.servlet.jsp.jstl-api</artifactId>
            <version>1.2.1</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.8</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20160212</version>
        </dependency>
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.5.0-b01</version>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>2.0.2-beta</version>
        </dependency>        
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency> 
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-all</artifactId>
            <version>1.3</version>
        </dependency>     
        <!--JSF Library-->
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-api</artifactId>
            <version>2.2.13</version>
        </dependency>
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.13</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <!--postgres-->
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.3-1100-jdbc41</version>
        </dependency>    
        <!--Hibernate Library-->    
        <!--se for mudar de versão precisa verificar as configuracoes de conexao-->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.1.0.Final</version>
        </dependency>
        <!--Log4j Libary-->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <!--PrimeFaces-->
        <dependency>
            <groupId>org.primefaces</groupId>
            <artifactId>primefaces</artifactId>
            <version>5.3</version>
        </dependency>
    
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <compilerArguments>
                        <endorseddirs>${endorsed.dir}</endorseddirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <archiveClasses>false</archiveClasses>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${endorsed.dir}</outputDirectory>
                            <silent>true</silent>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>javax</groupId>
                                    <artifactId>javaee-endorsed-api</artifactId>
                                    <version>7.0</version>
                                    <type>jar</type>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
<!--                    <url>http://10.1.1.99:8080/manager/</url>
                    <server>ubuntuServer</server>-->
                    <path>/IgrejaHabil</path>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <url>http://repository.primefaces.org/</url>
            <id>PrimeFaces-maven-lib</id>
            <layout>default</layout>
            <name>Repository for library PrimeFaces-maven-lib</name>
        </repository>
        <repository>
            <url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
            <id>RichFaces-maven-lib</id>
            <layout>default</layout>
            <name>Repository for library RichFaces-maven-lib</name>
        </repository>
    </repositories>
</project>
&#13;
&#13;
&#13;

的web.xml

&#13;
&#13;
<?xml version="1.0" encoding="UTF-8"?>

<web-app 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"
         id="WebApp_ID"
         version="3.1">
    
    <display-name>IgrejaHabil</display-name>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <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>
    <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>
   <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>
    
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
</web-app>
&#13;
&#13;
&#13;

问题是如果我将.war文件部署到Wildfly,它可以正常工作,问题只发生在Tomcat7上。

使用JDK 8u77,Tomcat7,Wildfly 9.0.2 Final,Primefaces v5.3,JSF 2.2

修改

AbstractBean.java

&#13;
&#13;
package br.com.koinonia.igrejahabil.bean;

import br.com.koinonia.igrejahabil.dao.AbstractDAOImpl;
import br.com.koinonia.igrejahabil.excecoes.NenhumUsuarioLogado;
import br.com.koinonia.igrejahabil.excecoes.NenhumaIgrejaAtiva;
import br.com.koinonia.igrejahabil.model.AbstractEntity;
import br.com.koinonia.igrejahabil.model.UsuarioLogado;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;

/**
 *
 * @author Julio
 * @param <T>
 * @param <U>
 */
public abstract class AbstractBean<T extends AbstractEntity, U extends AbstractDAOImpl> implements Serializable {

    protected final String SUCESSO = "sucesso";
    protected final String ERRO = "erro";

   
    private T obj = null;
    private U dao = null;

    private LazyDataModel lista;

    public AbstractBean() {
        // tem que criar o LazyDataModel aqui porque se criar no momento que chama, não funciona;
        this.lista = new LazyDataModel() {
            @Override
            public List load( int first, int pageSize, String sortField, SortOrder sortOrder, Map filters ) {
                setRowCount( ( int ) getDAO().getTotalRegistros( condicaoPadrao() ) );
                return getDAO().getLista( condicaoPadrao(), first, pageSize );
            }

            @Override
            public Object getRowKey( Object object ) {
                return ( ( T ) object ).getId();
            }
        };
    }

    public U getDAO() {
        if ( this.dao == null ) {
            try {
                this.dao = ( U ) this.getDAOGenerico().newInstance();
            } catch ( InstantiationException | IllegalAccessException ex ) {
                Logger.getLogger( AbstractBean.class.getName() ).log( Level.SEVERE, null, ex );
            }
        }

        return this.dao;
    }

    public T getObj() {
        if ( this.obj == null ) {
            try {
                this.obj = ( T ) getEntityGenerico().newInstance();
            } catch ( InstantiationException | IllegalAccessException ex ) {
                Logger.getLogger( AbstractBean.class.getName() ).log( Level.SEVERE, null, ex );
            }
        }

        return this.obj;
    }

    protected HttpServletRequest getRequest() {

        HttpServletRequest request = ( HttpServletRequest ) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        if ( request == null ) {
            throw new RuntimeException( "Sorry. Got a null request from faces context" );
        }
        return request;
    }

    public UsuarioLogado getUsuarioLogado() {
        UsuarioLogado result;
        try {
            result = new UsuarioLogado( this.getRequest() );
            return result;
        } catch ( NenhumUsuarioLogado ex ) {
            Logger.getLogger( AbstractBean.class.getName() ).log( Level.SEVERE, null, ex );
            throw new UnsupportedOperationException( "NenhumUsuarioLogado ainda não foi implementado" );
        }
    }

    public String salvar() {

        try {
            this.getDAO().salvar( this.obj );
            return SUCESSO;
        } catch ( Exception ex ) {
            Logger.getLogger( AbstractBean.class.getName() ).log( Level.SEVERE, null, ex );
            return ERRO;
        }
    }

    public String excluir( T obj ) {

        try {
            this.getDAO().excluir( obj );
            return SUCESSO;
        } catch ( Exception ex ) {
            Logger.getLogger( AbstractBean.class.getName() ).log( Level.SEVERE, null, ex );
            return ERRO;
        }
    }

    public String excluir( long id ) {
        T objeto = ( T ) this.getDAO().getById( id );
        return this.excluir( objeto );
    }

    public Criterion condicaoPadrao() {
        try {
            return Restrictions.eq( "igreja", this.getUsuarioLogado().getIgreja() );
        } catch ( NenhumaIgrejaAtiva ex ) {
            Logger.getLogger( AbstractBean.class.getName() ).log( Level.SEVERE, null, ex );
            throw new UnsupportedOperationException( "NenhumaIgrejaAtiva ainda não foi implementado" );
        }
    }

    public LazyDataModel getLista() {
        return this.lista;
    }

    public String editar( long id ) {
        this.obj = ( T ) this.getDAO().getById( id );
        return "";
    }

    public String novo() {
        try {
            this.obj = ( T ) this.getEntityGenerico().newInstance();
        } catch ( InstantiationException | IllegalAccessException ex ) {
            Logger.getLogger( AbstractBean.class.getName() ).log( Level.SEVERE, null, ex );
            return this.ERRO;
        }
        return "";
    }

    private Class getEntityGenerico() {
        return ( ( Class ) ( ( ParameterizedType ) getClass().getGenericSuperclass() ).getActualTypeArguments()[ 0 ] );
    }

    private Class getDAOGenerico() {
        return ( ( Class ) ( ( ParameterizedType ) getClass().getGenericSuperclass() ).getActualTypeArguments()[ 1 ] );
    }

}
&#13;
&#13;
&#13;

  

我认为这个问题不重复。我已经看到了很多ManagedBeans的问题,但不是像我的那样,因为它适用于Wildfly 9.0.2 Final但不适用于Tomcat 7

0 个答案:

没有答案