Bom galera,
estou com o seguinte problema.
Tenho uma classe Transportador com o
Municipio e UF mapeado como LAZY, porem quando vou editar este transportador
ele renderiza a view mais não seleciona o Municipio, antes de renderizar a
view eu preencho o selectOneMenu com os Municipios e Uf.
Estou usando JSF2, Primefaces 2.2.1, Mojarra
2.0.4 e Spring.
Se eu colocar EAGER no mapeamento funciona
corretamente, já debuguei, fiz diversos testes e nada.
Seguem as classes:
@Entity
@Table(name = "MUNICIPIO")
public class Municipio implements
Serializable {
private static final long
serialVersionUID = 1L;
@Id
@GeneratedValue(strategy
= GenerationType.IDENTITY)
private Long
idMunicipio;
private String
cMun;
private String
xMun;
@ManyToOne(fetch =
FetchType.LAZY)
@JoinColumn(name =
"IDUF")
private Uf
uf;
//getters, setters, hashCode and equals
omitidos
}
@Entity
@Table(name = "TRANSPORTADOR")
public
class Transportador implements Serializable {
private static final long
serialVersionUID = 1L;
@Id
@GeneratedValue(strategy
= GenerationType.IDENTITY)
private Long
idTransportador;
private String
xNome;
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name =
"IDMUNICIPIO")
private Municipio
municipio;
//getters, setters, hashCode and equals
omitidos
}
A view:
<h:outputLabel value="ESTADO:"
title="Estado"/>
<h:selectOneMenu
id="uf" value="#{transportadorBean.uf}" title="Selecione um
Estado" style="width: 15.5em"
required="true">
<f:selectItem
itemLabel="SELECIONE" />
<f:selectItems
value="#{transportadorBean.ufs}" var="a" itemValue="#{a}"
itemLabel="#{a.xUf}" />
<f:converter
converterId="converterUf" />
<f:ajax
render="municipio" event="change"
listener="#{transportadorBean.listaMunicipios}" />
</h:selectOneMenu>
<h:outputLabel value="MUNICÍPIO:" />
<h:selectOneMenu
id="municipio" value="#{transportadorBean.transportador.municipio}"
style="width: 15.5em”
required="true" title="Selecione um
município">
<f:selectItem
itemLabel="SELECIONE" itemValue="" />
<f:selectItems
value="#{transportadorBean.municipios}" var="b" itemValue="#{b}"
itemLabel="#{b.xMun}" />
<f:converter
converterId="converterMunicipio" />
</h:selectOneMenu>
ManagedBean:
//Inject, etc
TransportadorService
transportadorService;
Transportador transportador;
List<Uf> ufs;
List<Municipios>
municipios;
Uf uf;
public String editar() {
transportador =
transportadorService.getById(transportador.getIdTransportador());
ufs =
municipioService.consultarUfsBrasil();
uf =
transportador.getMunicipio().getUf();
municipios =
municipioService.consultarMunicipios(uf);
return
"transportadorForm";
}
Bom por enquanto é só.
Fico a disposição para
sugestões.
Obrigado.
Att Altieres de Matos
4º Ano de
Sistemas de Informação - UNIPAR - Paranavaí
Analista de Sistemas - D.S.
GOES & CIA LTDA
Cel.: (44) 9903-3987 / (44) 9931-8326
E-mail/MSN:
altitdb@xxxxxxxxxxx