14
respostas

Exercicio não funciona no Wildfly!! Me ajudem.

O exercicio simples da aula 2 não funciona no wildfly. Por quê?

package bean;

import javax.faces.bean.ManagedBean;

@ManagedBean
public class ProdutoBean {



    public void gravar() {
        System.out.println("Gravando livro ");
    }
}

<!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"> 

<h:head>
</h:head> 
<h:body>
<h1>Cadastro de Produtos</h1>
<h:form >
 <p:fieldset>

  <h:panelGrid columns="2">

     <h:commandButton value="Gravar" action= "#{produtoBean.Gravar}"/>
     </h:panelGrid>
    </p:fieldset>
</h:form>
</h:body> 
</html>

ERRO NO WILDFLY:

Context Path:/Loja
Servlet Path:/index.xhtml
Path Info:null
Query String:null
Stack Trace
javax.servlet.ServletException: javax.el.PropertyNotFoundException: /index.xhtml @17,68 action="#{produtoBean.Gravar}": Target Unreachable, identifier 'produtoBean' resolved to null
14 respostas

Oi Thiago, é alguma besteira.

O seu projeto está configurado corretamente e está compilando (nao tem nenhum error na view Problems)

Quando vc sobe o Wildfly aparece algum erro?

abs

Não.A página sobe normalmente. O erro é emitido apenas quando eu clico no botão gravar. Já não sei mais o que fazer.

Tenta uma vez usar @Names em vez de @ManagedBean.

Também, a El correta é action="#{produtoBean.gravar}"

abs

@Names não importou nada. Tentei @Named e também não funcionou. O erro persiste.

segue o web.xml: ?xml version="1.0"?>

Loja

index.xhtml Faces Servlet javax.faces.webapp.FacesServlet 1 Faces Servlet *.xhtml

Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0 23:06:18,483 INFO [org.jboss.modules] (main) JBoss Modules version 1.3.3.Final 23:06:20,260 INFO [org.jboss.msc] (main) JBoss MSC version 1.2.2.Final 23:06:20,583 INFO [org.jboss.as] (MSC service thread 1-6) JBAS015899: WildFly 8.2.1.Final "Tweek" starting 23:06:28,018 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found teste.war in deployment directory. To trigger deployment create a file called teste.war.dodeploy 23:06:28,019 INFO [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found Loja.war in deployment directory. To trigger deployment create a file called Loja.war.dodeploy 23:06:28,076 INFO [org.jboss.as.server] (Controller Boot Thread) JBAS015888: Creating http management service using socket-binding (management-http) 23:06:28,398 INFO [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 32) JBAS010280: Activating Infinispan subsystem. 23:06:28,421 INFO [org.jboss.as.webservices] (ServerService Thread Pool -- 48) JBAS015537: Activating WebServices Extension 23:06:28,416 WARN [org.jboss.as.txn] (ServerService Thread Pool -- 46) JBAS010153: Node identifier property is set to the default value. Please make sure it is unique. 23:06:28,416 INFO [org.jboss.as.security] (ServerService Thread Pool -- 45) JBAS013171: Activating Security Subsystem 23:06:28,449 INFO [org.jboss.as.jsf] (ServerService Thread Pool -- 38) JBAS012615: Activated the following JSF Implementations: [main] 23:06:28,587 INFO [org.xnio] (MSC service thread 1-4) XNIO version 3.3.0.Final 23:06:28,845 INFO [org.jboss.as.security] (MSC service thread 1-5) JBAS013170: Current PicketBox version=4.0.21.Final 23:06:29,136 INFO [org.jboss.as.connector.logging] (MSC service thread 1-8) JBAS010408: Starting JCA Subsystem (IronJacamar 1.1.9.Final) 23:06:29,365 INFO [org.jboss.as.naming] (ServerService Thread Pool -- 40) JBAS011800: Activating Naming Subsystem 23:06:29,624 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017502: Undertow 1.1.8.Final starting 23:06:29,624 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017502: Undertow 1.1.8.Final starting 23:06:30,326 INFO [org.wildfly.extension.io] (ServerService Thread Pool -- 31) WFLYIO001: Worker 'default' has auto-configured to 8 core threads with 64 task threads based on your 4 available processors 23:06:31,128 INFO [org.xnio.nio] (MSC service thread 1-4) XNIO NIO Implementation Version 3.3.0.Final 23:06:31,572 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 47) JBAS017527: Creating file handler for path /home/thiago/wildfly-8.2.1.Final/welcome-content 23:06:32,353 INFO [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 27) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3) 23:06:32,358 INFO [org.jboss.as.connector.deployers.jdbc] (MSC service thread 1-2) JBAS010417: Started Driver service with driver-name = h2 23:06:33,934 INFO [org.jboss.as.naming] (MSC service thread 1-1) JBAS011802: Starting Naming Service 23:06:33,937 INFO [org.jboss.as.mail.extension] (MSC service thread 1-2) JBAS015400: Bound mail session [java:jboss/mail/Default] 23:06:34,027 INFO [org.jboss.remoting] (MSC service thread 1-4) JBoss Remoting version 4.0.7.Final 23:06:34,101 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017525: Started server default-server. 23:06:34,273 INFO [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) JBAS015012: Started FileSystemDeploymentService for directory /home/thiago/wildfly-8.2.1.Final/standalone/deployments 23:06:34,282 INFO [org.jboss.as.server.deployment] (MSC service thread 1-5) JBAS015876: Starting deployment of "Loja.war" (runtime-name: "Loja.war") 23:06:34,282 INFO [org.jboss.as.server.deployment] (MSC service thread 1-6) JBAS015876: Starting deployment of "teste.war" (runtime-name: "teste.war") 23:06:34,449 INFO [org.wildfly.extension.undertow] (MSC service thread 1-3) JBAS017531: Host default-host starting 23:06:35,090 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017519: Undertow HTTP listener default listening on localhost/127.0.0.1:8080 23:06:35,639 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-5) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS] 23:06:38,755 INFO [org.jboss.ws.common.management] (MSC service thread 1-3) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.3.2.Final 23:06:41,007 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-6) Inicializando Mojarra 2.2.8-jbossorg-1 20140822-1131 para o contexto '/Loja' 23:06:41,012 INFO [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-1) Inicializando Mojarra 2.2.8-jbossorg-1 20140822-1131 para o contexto '/teste' 23:06:43,494 INFO [org.wildfly.extension.undertow] (MSC service thread 1-1) JBAS017534: Registered web context: /teste 23:06:44,207 INFO [org.primefaces.webapp.PostConstructApplicationEventListener] (MSC service thread 1-6) Running on PrimeFaces 5.3 23:06:44,208 INFO [org.wildfly.extension.undertow] (MSC service thread 1-6) JBAS017534: Registered web context: /Loja 23:06:44,279 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "teste.war" (runtime-name : "teste.war") 23:06:44,280 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "Loja.war" (runtime-name : "Loja.war") 23:06:44,447 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management 23:06:44,449 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990 23:06:44,449 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.2.1.Final "Tweek" started in 28413ms - Started 821 of 882 services (102 services are lazy, passive or on-demand) 23:06:45,737 INFO [org.hibernate.validator.internal.util.Version] (default task-2) HV000001: Hibernate Validator 5.1.3.Final 23:06:49,044 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-8) #{bean.gravar}: javax.el.PropertyNotFoundException: /index.xhtml @17,73 action="#{bean.gravar}": Target Unreachable, identifier 'bean' resolved to null: javax.faces.FacesException: #{bean.gravar}: javax.el.PropertyNotFoundException: /index.xhtml @17,73 action="#{bean.gravar}": Target Unreachable, identifier 'bean' resolved to null at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) [jsf-impl-2.2.8-jbossorg-1.jar:] at javax.faces.component.UICommand.broadcast(UICommand.java:315) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8] at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8] at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8] at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) [jsf-impl-2.2.8-jbossorg-1.jar:] at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.2.8-jbossorg-1.jar:] at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) [jsf-impl-2.2.8-jbossorg-1.jar:] at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8] at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:248) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:77) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:167) [undertow-servlet-1.1.8.Final.jar:1.1.8.Final] at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:761) [undertow-core-1.1.8.Final.jar:1.1.8.Final] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_92] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_92] at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_92] Caused by: javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /index.xhtml @17,73 action="#{bean.gravar}": Target Unreachable, identifier 'bean' resolved to null at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:94) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8] at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) [jsf-impl-2.2.8-jbossorg-1.jar:] ... 33 more Caused by: javax.el.PropertyNotFoundException: /index.xhtml @17,73 action="#{bean.gravar}": Target Unreachable, identifier 'bean' resolved to null at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107) [jsf-impl-2.2.8-jbossorg-1.jar:] at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) [jboss-jsf-api_2.2_spec-2.2.8.jar:2.2.8] ... 34 more

23:06:49,082 SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-8) javax.faces.el.EvaluationException: javax.el.PropertyNotFoundException: /index.xhtml @17,73 action="#{bean.gravar}": Target Unreachable, identifier 'bean' 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:646) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:58) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:70) at io.undertow.security.handlers.SecurityInitialHandler.handleRequest(SecurityInitialHandler.java:76) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:261) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:248) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:77) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:167) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:199) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:761) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: javax.el.PropertyNotFoundException: /index.xhtml @17,73 action="#{bean.gravar}": Target Unreachable, identifier 'bean' resolved to null at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:107) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ... 34 more

Oi Thiago,

vc tem algum JAR no seu projeto web (não deveria)?

abs

Não entendi. Tenho as libs. Você pode disponibilizar esse exemplo funcionado?

Então o Wildfly já tem os libs do jsf, jpa e cdi embutido. Provável que isso esteja dando problemas.

Eu explique isso no 3 modulo sobre JSF e mostro como usar JSF com CDI ou Spring no Tomcat e Wildfly:

https://cursos.alura.com.br/course/jsf-cdi

No curso também tem o download do projeto, mas vc precisa configurar mais coisas no wildfly, por exemplo o datasource.

abs

Thiago, não é melhor fazer o curso com a infra que o instrutor indica, depois de terminar, tentar migrar para o servidor de aplicação? Digo isso porque você pode esfriar e ficar batendo cabeça com coisa de infraestrutura quando podia estar já avançando no curso. É só uma sugestão. Aliás, como Nico disse, em outro módulo ele usa o wildfly. Quem sabe migrar par ao wildfly nesse módulo seria o ponto perfeito.

Oi Thiago,

nao sei exatamente o seu motivo de usar Wildfly, mas vai devagar :) Um servidor de aplicação é algo complexo. No caso dessa aplicação, todas as bibliotecas são fornecidas pelo wildfly mas as configurações dentro da app precisam estar corretas.

Eu aconselho assisti primeiro todos os modulos sobre JSF, e depois o treinamento EJB. Isso vai te dar uma boa base para se dar bem com Wildfly.

abs

Boa tarde Thiago,

Pelo que eu vi você está chamando #{produtoBean.Gravar()} quando o seu método é gravar() em minusculo. Ele falou que não encontrou aquele método em especifico.

Se caso houver a troca do nome e o erro persistir tente desinstalar o wildfly e instalar novamente usando o eclipse. Mas creio que o erro é a chamada do método não existente.

Abraço! :D

Boa tarde Gleidson,

Sim. Eu já realizei essa alteração, mas o erro persiste. Eu já fiz aulas, entretanto quero realizar os exercícios do "zero" e não pegar apenas os.zips das aulas.

Oi Thiago,

vc já configurou o datasource?

abs

Não porquê eu ainda não estou realizando a persistência.

Blz, agora apague todos os seu JARs da pasta WEB-INF/lib, menos o JAR do Primefaces.

Além disso, você deve adicionar o Server Runtime do Wildfly no seu projeto. Isso também deveria resolver o problema porque o @Named não foi encontrado.

Se o projeto compila corretamente, tente subir o Wildfly novamente.

abs