Solucionado (ver solução)
Solucionado
(ver solução)
2
respostas

javax.el.PropertyNotFoundException JSF + CDI + HIBERNATE

Já procurei no guj, stackoverflow e nenhuma solução resolveu, favor se puderem me ajudar a encontrar a solução.

erro

ADVERTÊNCIA: #{pessoaBean.salvar}: javax.el.PropertyNotFoundException: /index.xhtml @47,118 action="#{pessoaBean.salvar}": Target Unreachable, identifier 'pessoaBean' resolved to null
javax.faces.FacesException: #{pessoaBean.salvar}: javax.el.PropertyNotFoundException: /index.xhtml @47,118 action="#{pessoaBean.salvar}": Target Unreachable, identifier 'pessoaBean' resolved to null
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    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:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    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:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /index.xhtml @47,118 action="#{pessoaBean.salvar}": Target Unreachable, identifier 'pessoaBean' resolved to null
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:94)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    ... 26 more
Caused by: javax.el.PropertyNotFoundException: /index.xhtml @47,118 action="#{pessoaBean.salvar}": Target Unreachable, identifier 'pessoaBean' resolved to null
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    ... 27 more

ago 24, 2017 2:42:38 PM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
GRAVE: javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /index.xhtml @47,118 action="#{pessoaBean.salvar}": Target Unreachable, identifier 'pessoaBean' resolved to null
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:94)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    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:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    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:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: javax.el.PropertyNotFoundException: /index.xhtml @47,118 action="#{pessoaBean.salvar}": Target Unreachable, identifier 'pessoaBean' resolved to null
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
    ... 27 more

web.xml

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

    <display-name>sia</display-name>

    <servlet>
        <servlet-name>FacesServlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>FacesServlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>primefaces.FONT_AWESOME</param-name>
        <param-value>true</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>

context.xml e bean.xml

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

    <Resource name="BeanManager"
        auth="Container"
        type="javax.enterprise.inject.spi.BeanManager"
        factory="org.jboss.weld.resources.ManagerObjectFactory"/>

</Context>


<beans>

    <interceptors>
        <class>br.com.sia.managers.TransactionManagers</class>
    </interceptors>

</beans>

persistence.xml

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0">

    <persistence-unit name="livraria" transaction-type="RESOURCE_LOCAL">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <class>br.com.sia.models.Pessoa</class>

        <properties>

            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="toor" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost/siadb" />
            <property name="hibernate.max_fetch_depth" value="3" />

            <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" />
            <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            <property name="hibernate.show_sql" value="true" />

        </properties>

    </persistence-unit>

</persistence>

PessoaBean

package br.com.sia.beans;

import java.io.Serializable;
import java.util.List;

import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;

import br.com.sia.annotations.Transactional;
import br.com.sia.models.Pessoa;
import br.com.sia.repository.PessoaRepository;

@Named
@ViewScoped
public class PessoaBean implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    private PessoaRepository pessoaRepository;

    @Inject
    private Pessoa pessoa;

    public Pessoa getPessoa() {
        return this.pessoa;
    }

    @Transactional
    public String salvar() {
        pessoaRepository.save(pessoa);
        return "index?faces-redirect=true";
    }

    public List<Pessoa> getPessoas(){
        return pessoaRepository.findAll();
    }

}

Index.xhtml

<?xml version="1.0" encoding="UTF-8" ?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets">

<h:head>
    <title>Sistema de Locação</title>
</h:head>

<h:body>

    <h1>#{IndexBean.message}</h1>

    <p:fieldset legend="Locação de Veículos">

        <div class="ui-g-12 ui-md-4">
            <div class="ui-inputgroup">
                <p:inputText placeholder="Informe o CPF" />
                <p:commandButton icon="fa fa-search" styleClass="white-button" />
            </div>
        </div>

        <h:form>

            <p:commandButton id="movieBtn" value="Novo Cliente" type="button" />
            <p:overlayPanel id="moviePanel" for="movieBtn" hideEffect="fade"
                dynamic="true" style="width:600px">
                <p:panel header="Cadastro de Cliente">
                    <p:messages />
                    <h:panelGrid columns="2" columnClasses="label, value">

                        <p:outputLabel value="Nome:" for="nome" />
                        <p:inputText id="nome" />

                        <p:outputLabel value="CPF:" for="cpf" />
                        <p:inputText id="cpf" />

                        <p:outputLabel value="Telefone:" for="telefone" />
                        <p:inputText id="telefone" />

                        <p:outputLabel value="Endereço:" for="endereco" />
                        <p:inputText id="endereco" />

                        <p:commandButton value="Salvar" id="btn-salvar"
                            styleClass="ui-priority-primary" action="#{pessoaBean.salvar}" update=":pessoas-cadastradas" process="@form"/>

                    </h:panelGrid>
                </p:panel>

            </p:overlayPanel>
        </h:form>


        <h:form id="pessoas-cadastradas">

            <p:panel header="Clientes">
                <p:messages />

                <p:dataTable var="pessoa" value="#{pessoaBean.pessoas}">
                    <p:column headerText="CPF">
                        <h:outputText value="#{pessoa.cpf}" />
                    </p:column>

                    <p:column headerText="Nome">
                        <h:outputText value="#{pessoa.nome}" />
                    </p:column>

                    <p:column headerText="Alugar">
                        <h:outputText value="#{car.brand}" />
                    </p:column>

                    <p:column headerText="Settings">
                        <p:menuButton value="Options">
                            <p:menuitem value="Save" actionListener="#{menuView.save}"
                                update="messages" icon="ui-icon-disk" />
                            <p:menuitem value="Update" actionListener="#{menuView.update}"
                                update="messages" icon="ui-icon-arrowrefresh-1-w" />
                            <p:menuitem value="Delete" actionListener="#{menuView.delete}"
                                ajax="false" icon="ui-icon-close" />
                            <p:separator />
                            <p:menuitem value="Homepage" url="http://www.primefaces.org"
                                icon="ui-icon-extlink" />
                        </p:menuButton>
                    </p:column>
                </p:dataTable>

            </p:panel>

        </h:form>


        <p:outputLabel for="console" value="Serviço" />
        <p:selectOneMenu id="console" style="width:125px">
            <f:selectItem itemLabel="Select One" itemValue="" />
            <f:selectItem itemLabel="Xbox One" itemValue="Xbox One" />
            <f:selectItem itemLabel="PS4" itemValue="PS4" />
            <f:selectItem itemLabel="Wii U" itemValue="Wii U" />
        </p:selectOneMenu>

    </p:fieldset>

</h:body>

</html>
2 respostas
solução!

Fala Gilmar, tudo bem ?

A EL não está encontrando o bean disponível quando vai ser interpretada, por isso diz que foi resolvido para null, o que resulta na exception.

Tente usar #{PessoaBean.salvar}

O erro era porque estava usando a dependência errada no maven, coloquei a correta, e funcionou.

<dependency>
            <groupId>org.jboss.weld.servlet</groupId>
            <artifactId>weld-servlet</artifactId>
            <version>2.4.4.Final</version>
        </dependency>