1
Hi, guys. I’m creating a program that manipulates human and livestock records. In this program, on the livestock register screen, I am creating two Selectonemenu of the first faces. One is of type of cattle and the other of breed of cattle. These two Selectonemenus are dependent. That is, for example, if the user selects "bovine" in the type, in the breed the bovine breeds must appear to be chosen.
After I started implementing the Selectonemenu (to be more precise, when I implemented the cattle type), a build error started to appear WELD-001456: Argument resolvedBean must not be null.
I searched the internet and several articles talked to change the version of Weld, but I tried and the error persists. The current version I am using in the project is 2.3.5 Final. I tried changing this version in pom.xml and updating the Maven project, but the error persists.
This error appears when I try to load the cattle registration page. One thing I find strange is that there are times that in the Eclipse console appears the error of WELD-001456 and there are times that the error appears Cannot find Component for Expression "typed" referenced from "j_idt33:type"..
In addition, in the console sometimes appears in black letter, a message warning that it was not possible to perform the inject, but this message also does not appear every time.
I’m sending you the code of the files I believe are related to.
Cadastrogado.xhtml
<ui:define name="titulo">#{cadastroGadoBean.editando ? "Edição de Gado" : "Novo Gado"}</ui:define>
<ui:define name="corpo">
<f:metadata>
<o:viewParam name="gado" value="#{cadastroGadoBean.gado}"/>
<f:event listener="#{cadastroGadoBean.inicializar}" type="preRenderView"/>
</f:metadata>
<h:form>
<h1>#{cadastroGadoBean.editando ? "Edição de Gado" : "Novo Gado"}</h1>
<p:messages autoUpdate="true" closable="true" />
<p:toolbar style="margin-top: 20px">
<p:toolbarGroup>
<p:button value="Novo" outcome="/gado/CadastroGado" />
<p:commandButton value="Salvar" id="botaoSalvar"
action="#{cadastroGadoBean.salvar}" update="@form" />
</p:toolbarGroup>
<p:toolbarGroup align ="right">
<p:button value="Pesquisar" outcome="/gado/PesquisaGado"/>
</p:toolbarGroup>
</p:toolbar>
<p:panelGrid columns="2" id="painel"
style="width: 100%; margin-top: 20px" columnClasses="rotulo, campo">
<p:outputLabel value="Tipo" for="tipo"/>
<p:selectOneMenu id="tipo" value="#{cadastroGadoBean.gado.tipogado}" label="Tipo"
required="true" requiredMessage="Informe o tipo do gado">
<f:selectItem itemLabel="" noSelectionOption = "true"/>
<f:selectItems
value="#{cadastroGadoBean.listTipo}" var="tipogado"
itemValue="#{tipogado}" itemLabel="#{tipogado.nomeTipo}" />
<p:ajax listener="#{cadastroGadoBean.carregarRacas}" update="tipogado"/>
</p:selectOneMenu>
<p:outputLabel value="Raça" for="gadoRaca" />
<p:inputText id="gadoRaca" size="20" maxlength="80"
value="#{cadastroGadoBean.gado.gadoRaca}" required="true"
requiredMessage="Por favor, informe a raça do gado"
validatorMessage="formato de raça inválida">
<f:validateRegex pattern="^[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ ]+$"/>
</p:inputText>
<p:outputLabel value="Peso(em Kg)" for="gadoPeso" />
<p:inputMask id="gadoPeso" size="10" maxlength="80"
value="#{cadastroGadoBean.gado.gadoPeso}" required="true" mask="999"
requiredMessage="Por favor, informe o peso do gado">
<f:convertNumber minFractionDigits="2" />
<f:validateDoubleRange minimum="1" maximum="30"/>
</p:inputMask>
<p:outputLabel value="Sexo" for="sexo" />
<p:selectOneRadio id="sexo" value="#{cadastroGadoBean.gado.sexo}" required="true"
requiredMessage="Por favor, informe o sexo do gado">
<f:selectItem itemLabel="Macho" itemValue="Macho"/>
<f:selectItem itemLabel="Fêmea" itemValue="Fêmea"/>
</p:selectOneRadio>
<p:outputLabel value="Nascimento" for="gadoNasc" />
<p:calendar id="gadoNasc" size="10" pattern="dd/MM/yyyy"
value="#{cadastroGadoBean.gado.gadoNasc}" maxdate="#{cadastroGadoBean.dataAtual}"
locale="pt_BR" required="true"
requiredMessage="Por favor, informe a data de nascimento"/>
<p:outputLabel value="Finalidade do Gado" for="gadoFinalidade" />
<p:inputText id="gadoFinalidade" size="20" maxlength="80"
value="#{cadastroGadoBean.gado.gadoFinalidade}" required="true"
requiredMessage="Por favor, informe a finalidade do gado"
validatorMessage="formato de nome inválido">
<f:validateRegex pattern="^[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ ]+$"/>
</p:inputText>
<p:outputLabel value="Tag" for="tag"/>
<p:selectOneMenu value="#{cadastroGadoBean.gado.tag}" label="Tag" id="tag" filter="true" filterMatchMode="contains" required="true"
requiredMessage="Por favor, informe a tag acoplada ao gado">
<f:selectItem itemLabel="Selecione" noSelectionOption = "true"/>
<f:selectItems
value="#{cadastroGadoBean.listTags}"
var="tag"
itemValue="#{tag}"
itemLabel="#{tag.descricao}" />
</p:selectOneMenu>
<p:outputLabel value="Usuario" for="usuario"/>
<p:selectOneMenu value="#{cadastroGadoBean.gado.usuario}" label="Usuario" id="usuario" filter="true" filterMatchMode="contains"
required="true"
requiredMessage="Por favor, informe o usuario que está efetuando o cadastro">
<f:selectItem itemLabel="Selecione" noSelectionOption = "true"/>
<f:selectItems
value="#{cadastroGadoBean.listUsuario}"
var="usuario"
itemValue="#{usuario}"
itemLabel="#{usuario.nome}" />
</p:selectOneMenu>
</p:panelGrid>
</h:form>
</ui:define>
Cadastrogadobean.java
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.model.SelectItem;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import com.sisRastrbov.model.Gado;
import com.sisRastrbov.model.Raca;
import com.sisRastrbov.model.Tag;
import com.sisRastrbov.model.TipoGado;
import com.sisRastrbov.model.Usuario;
import com.sisRastrbov.repository.RacaRep;
import com.sisRastrbov.repository.TagsRep;
import com.sisRastrbov.repository.TipoGadoRep;
import com.sisRastrbov.repository.UsuariosRep;
import com.sisRastrbov.services.CadastroGadoService;
import com.sisRastrbov.util.jsf.FacesUtil;
@Named
@ViewScoped
public class CadastroGadoBean implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private TipoGadoRep tipoGados;
@Inject
private TagsRep tagsRep;
@Inject
private UsuariosRep usuarios;
@Inject
private CadastroGadoService cadastroGadoService;
private Gado gado;
private Tag tag;
private Usuario usuario;
private TipoGado tipogado;
private List<SelectItem> listTipo;
private List<SelectItem> listRaca;
private List<SelectItem> listTags;
private List<SelectItem> listUsuario;
public Date getDataAtual() {
return new Date();
}
public CadastroGadoBean() {
limpar();
}
public boolean isEditando() {
boolean resultado = false;
if (this.gado != null) {
resultado = gado.getGadoId() != null;
}
return resultado;
}
public void inicializar() {
listTipo = new ArrayList<SelectItem>();
listTags = new ArrayList<SelectItem>();
listUsuario = new ArrayList<SelectItem>();
List<TipoGado> tipos = tipoGados.raizes();
List<Tag> tags = tagsRep.raizes();
List<Usuario> listaUsu = usuarios.listaDeUsu();
for (TipoGado tg : tipos) {
SelectItem item = new SelectItem();
item.setLabel(tg.getNomeTipo());
item.setValue(tg);
listTags.add(item);
System.out.println(listTipo);
}
for (Tag t : tags) {
SelectItem item = new SelectItem();
item.setLabel(t.getDescricao());
item.setValue(t);
listTags.add(item);
System.out.println(listTags);
}
for (Usuario u : listaUsu) {
SelectItem item = new SelectItem();
item.setLabel(u.getNome());
item.setValue(u);
listUsuario.add(item);
}
if(!isEditando()){
gado.setgadoStatus("Ativo");
}
if (this.tipogado != null) {
tipos = tipoGados.raizes();
}
}
public void limpar() {
gado = new Gado();
listTags = new ArrayList<SelectItem>();
}
public void salvar() {
this.gado = cadastroGadoService.salvar(this.gado);
limpar();
FacesUtil.addInfoMessage("Gado salvo com sucesso!");
}
public void carregarRacas(){
listRaca = new ArrayList<SelectItem>();
List<Raca> racas = RacaRep.racasDe(gado.getTipogado());
for (Raca r : racas) {
SelectItem item = new SelectItem();
item.setLabel(r.getNome());
item.setValue(r);
listRaca.add(item);
}
}
public Gado getGado() {
return gado;
}
public void setGado(Gado gado) {
this.gado = gado;
if (this.gado != null) {
this.tag = this.gado.getTag();
}
}
public List<SelectItem> getListTags() {
return listTags;
}
public void setListTags(List<SelectItem> listTags) {
this.listTags = listTags;
}
public List<SelectItem> getListTipo() {
return listTipo;
}
public void setListTipo(List<SelectItem> listTipo) {
this.listTipo = listTipo;
}
public Tag getTag() {
return tag;
}
public void setTag(Tag tag) {
this.tag = tag;
}
public Usuario getUsuario() {
return usuario;
}
public void setUsuario(Usuario usuario) {
this.usuario = usuario;
}
public List<SelectItem> getListUsuario() {
return listUsuario;
}
public void setListUsuario(List<SelectItem> listUsuario) {
this.listUsuario = listUsuario;
}
public TipoGado getTipogado() {
return tipogado;
}
public void setTipogado(TipoGado tipogado) {
this.tipogado = tipogado;
}
}
Java typewriter.
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "tipoGado")
public class TipoGado {
String nomeTipo;
@Id
@Column(name = "nomeTipo")
public String getNomeTipo() {
return nomeTipo;
}
public void setNomeTipo(String nomeTipo) {
this.nomeTipo = nomeTipo;
}
}
Raca.java
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "raca")
public class Raca {
private String nome;
private TipoGado tipogado;
@Id
@Column(name = "racaNome")
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
@ManyToOne
@JoinColumn(name = "nomeTipo")
public TipoGado getTipogado() {
return tipogado;
}
public void setTipogado(TipoGado tipogado) {
this.tipogado = tipogado;
}
}
Tipogadorep.java
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import com.sisRastrbov.model.TipoGado;
public class TipoGadoRep implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private EntityManager manager;
public List<TipoGado> raizes(){
return manager.createQuery("from TipoGado",TipoGado.class).getResultList();
}
public List<TipoGado> listarTipoGado() {
List<TipoGado> tipos = new ArrayList<TipoGado>();
tipos = manager.createQuery("from TipoGado", TipoGado.class).getResultList();
return tipos;
}
}
Racarep.java
import java.io.Serializable;
import java.util.List;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import com.sisRastrbov.model.Raca;
import com.sisRastrbov.model.TipoGado;
public class RacaRep implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private static EntityManager manager;
public static List<Raca> racasDe(TipoGado tipogado){
return manager.createQuery("from Raca where nomeTipo = :raiz", Raca.class)
.setParameter("raiz", tipogado).getResultList();
}
}
You are updating in typeface but this component does not exist, see:
<p:ajax listener="#{cadastroGadoBean.carregarRacas}" update="tipogado"/>
update the correct component.– Dilnei Cunha