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

Target Unreachable, identifier 'sorteioBean' resolved to null

Boa tarde, estou com o seguinte javax.el.PropertyNotFoundException ao tentar criar um sorteio.

Exception:

16:02:46,737 WARNING [javax.enterprise.resource.webcontainer.jsf.lifecycle] (default task-9) /sorteio.xhtml @18,55 value="#{sorteioBean.sorteio.nome}": Target Unreachable, identifier 'sorteioBean' resolved to null: javax.el.PropertyNotFoundException: /sorteio.xhtml @18,55 value="#{sorteioBean.sorteio.nome}": Target Unreachable, identifier 'sorteioBean' resolved to null

Procurei na web e não acho nada concreto para solucionar, se alguém poder ajudar, fico grato.

sorteio.xhtml

<?xml version="1.0" encoding="utf-8" ?>
<!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:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:f="http://java.sun.com/jsf/core">
<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Novo Sorteio</title>
</h:head>
<h:body>
    <p:messages autoUpdate="true" />

    <h:form>

        <p:panelGrid columns="2">
            <p:outputLabel value="Nome:" />
            <p:inputText value="#{sorteioBean.sorteio.nome}" />
            <p:commandButton value="Sortear" action="#{sorteioBean.sortear()}"
                ajax="false" update="tabelaPares" />
        </p:panelGrid>

    </h:form>

    <p:dataTable id="tabelaPares" value="#{sorteioBean.listPares}"
        var="par" rows="10" paginator="true">

        <p:column>
            <f:facet name="header">Sorteio</f:facet>
            <p:outputLabel value="#{par.sorteio.nome}" />
        </p:column>

        <p:column>
            <f:facet name="header">Amigo</f:facet>
            <p:outputLabel value="#{par.amigo}" />
        </p:column>

        <p:column>
            <f:facet name="header">Amigo Oculto</f:facet>
            <p:outputLabel value="#{par.amigoOculto}" />
        </p:column>

    </p:dataTable>

</h:body>
</html>

SorteioBean.java

package br.com.caelum.auron.bean;

import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;

import br.com.caelum.auron.dao.ParticipanteDao;
import br.com.caelum.auron.dao.SorteioDao;
import br.com.caelum.auron.exception.SorteioException;
import br.com.caelum.auron.modelo.Par;
import br.com.caelum.auron.modelo.Sorteador;
import br.com.caelum.auron.modelo.Sorteio;

@Named
@RequestScoped
public class SorteioBean {

    private Sorteio sorteio = new Sorteio();
    private Sorteador sortador;

    @Inject
    private ParticipanteDao pDao;
    @Inject
    private SorteioDao sDao;

    public Sorteio getSorteio() {
        return sorteio;
    }

    public void sortear() {

        try {
            sortador = new Sorteador(pDao.getLista(), sorteio);
            sortador.sortear();
            sDao.persist(sorteio);

        } catch (SorteioException e) {
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(e.getMessage()));
        }
    }

    public List<Par> getListPares() {

        return sDao.getPares();
    }
}

Sorteio.java

package br.com.caelum.auron.modelo;

import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
public class Sorteio {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;

    @NotEmpty
    private String nome;

    @OneToMany(mappedBy = "sorteio", cascade = CascadeType.PERSIST)
    private Set<Par> pares = new LinkedHashSet<>();

    public Set<Par> getPares() {
        return Collections.unmodifiableSet(this.pares);
    }

    public void adicionaPar(Par par) {
        pares.add(par);
    }

    public String getNome() {
        return nome;
    }

    public int getQuantidadePares() {
        return pares.size();
    }

    public void setNome(String nome) {
        this.nome = nome;
    }
}
3 respostas
solução!

Oi Augusto

Você colocou o arquivo beans.xml no projeto?

Sim no curso ele é gerado automaticamente através do JBoss Tools, o estranho que os demais beans com importes exatamente idênticos e funcionalidade iguais, funcionam e somente essa não funciona, já me deu mor dor de cabeça acho que vou fazer tudo novamente. :(

Conseguiu resolver isso Augusto José? Estou com esse problema tb.

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software