pessoal, estou com problemas para atualizar um rich:comboBox a partir de outro… pelo que eu to vendo o método “atualizaCidades” nao esta sendo nem chamado… alguem sabe o que pode ser? estou usando JSF + RichFaces + Spring + JPA + Hibernate. segue meu código:
package br.com.sgiweb.backingbeans;
import br.com.sgiweb.dao.CidadeDAO;
import br.com.sgiweb.dao.UfDAO;
import br.com.sgiweb.entidades.Cidade;
import br.com.sgiweb.entidades.Uf;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.faces.model.SelectItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
/**
*
* @author pc
*/
@Component("enderecoBean")
@Scope("session")
public class EnderecoBean {
@Autowired
private UfDAO ufDAO;
@Autowired
private CidadeDAO cidadeDAO;
private String estado;
private List<SelectItem> cidades = new ArrayList<SelectItem>();
public Collection<SelectItem> getUfs() {
List<Uf> lista = ufDAO.listar();
Collection comboValue = new ArrayList();
for (Uf uf : lista) {
comboValue.add(new SelectItem(uf.getDsUf(), uf.getIdUf().toString()));
}
return comboValue;
}
public void atualizaCidades() {
System.out.println("Estado ----------------" + getEstado());
List<Cidade> lista = cidadeDAO.consultaPorUf(Integer.parseInt(getEstado()));
getCidades().clear();
for (Cidade cidade : lista) {
getCidades().add(new SelectItem(cidade.getDsCidade(), cidade.getIdCidade().toString()));
}
}
/**
* @return the estado
*/
public String getEstado() {
return estado;
}
/**
* @param estado the estado to set
*/
public void setEstado(String estado) {
this.estado = estado;
}
/**
* @return the cidades
*/
public Collection<SelectItem> getCidades() {
return cidades;
}
/**
* @param cidades the cidades to set
*/
public void setCidades(List<SelectItem> cidades) {
this.cidades = cidades;
}
}
e no xhtml:
<div class="form">
<div class="form_row">
<h:outputLabel value="Estado: " styleClass="left" for="estado"/>
<rich:comboBox id="estado" styleClass="form_input"
value="#{enderecoBean.estado}" defaultLabel="Selecione...">
<f:selectItems value="#{enderecoBean.ufs}"/>
<a4j:support event="onchange" reRender="cidade" action="#{enderecoBean.atualizaCidades}"/>
</rich:comboBox>
</div>
<div class="form_row">
<h:outputLabel value="Cidade: " styleClass="left" for="cidade"/>
<rich:comboBox id="cidade" styleClass="form_input" defaultLabel="Selecione..." >
<f:selectItems value="#{enderecoBean.cidades}"/>
</rich:comboBox>
</div>
</div>