Iae galera, blz ?
Seguinte, tenho um problema que acredito ser simples ( para quem sabe mexer, claro)
Tenho 2 tabelas, uma de estado e outra de cidade, coisa simples.
Gostaria de lista em uma pagina xhtml, o nome da cidade (tabela cidade) e o respectivo estado q esta cidade pertence.
Segue abaixo as entidades, beans e xhtml pra vcs entenderem
Entidade Cidade
@Entity
@Table(name = "cidade")
public class Cidade implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "cid_id")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long cidId;
@Column(name = "cid_nome")
private String cidNome;
@ManyToOne()
@JoinColumn(name = "est_id")
private Estado estId;
@Entity
@Table(name = "estado")
public class Estado implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "est_id")
private Long estId;
@Basic(optional = false)
@Column(name = "est_nome")
private String estNome;
@Column(name = "est_sigla")
private String estSigla;
@OneToMany(mappedBy ="estId")
private Collection<Cidade> cidade;
public class EstadoBean {
public List<Estado> getList() {
List<Estado> lista;
GenericDao<Estado> dao = new GenericDao<Estado>(Estado.class);
lista = dao.list();
return lista;
}
}
Pagina xhtml
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./../template/template.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:rich="http://richfaces.org/rich">
<ui:define name="conteudo">
<div class="menu">
<h:form>
<rich:spacer width="100%" height="15"/>
<rich:dataTable value="#{estado.list}" var="p">
<rich:column>
<f:facet name="header"><h:outputText value="Nome"/></f:facet>
<h:outputText value="#{p.estNome}"/>
</rich:column>
<rich:column>
<f:facet name="header"><h:outputText value="Nome"/></f:facet>
<h:outputText value="#{p.estSigla}"/>
</rich:column>
<rich:column>
<f:facet name="header"><h:outputText value="Nome"/></f:facet>
<h:outputText value="#{p.cidade[].cidNome}"/>
</rich:column>
<!--<rich:column>
<f:facet name="header"><h:outputText value="Editar"/></f:facet>
<h:commandLink action="{cidade.prepara}" value="#" id="link">
Editar<f:param name="idC" value="{p.proId}"/>
</h:commandLink>
</rich:column>-->
</rich:dataTable>
<rich:spacer width="100%" height="15"/>
</h:form>
Eu consigo lista só estado, ou Só as cidades, mas os 2 nao to conseguindo