我想加载两个primefaces selectOneMenu但只有一个selectBase选择。
班级国家/地区:
@Entity
@Table(name = "COUNTRY")
public class Country implements Serializable{
private static final long serialVersionUID = -2160543740997716714L;
@Id
@Column(name = "ID_COUNTRY")
private Long idTCountry;
@Column(name = "LIBELLE_COUNTRY")
private String libelleCountry;
@OneToMany(mappedBy="country")
private List<City> Cities;
班级城市
@Entity
@Table(name = "CITY")
public class City implements Serializable{
private static final long serialVersionUID = -1617401771255693322L;
@Id
@Column(name = "ID_CITY")
private Long idCity;
@ManyToOne
@JoinColumn(name="COUNTRY")
private Country country;
@Column(name = "LIBELLE")
private String libelle;
如何在XHTML中动态加载那些牵引selectOneMenu?
我做了这个,但它没有用:
<p:outputLabel for="country" value="Country: " />
<p:selectOneMenu id="country" value="#{countryView.selectedCountry}" style="width:150px">
<p:ajax listener="#{countryView.onTypeChange}" update="city" />
<f:selectItems value="#{countryView.countries}" itemLabel="#{selectedType.libelleCountry}" var="selectedCountry" />
</p:selectOneMenu>
<p:outputLabel for="city" value="City: " />
<p:selectOneMenu id="city" value="#{countryView.selectedCity}" style="width:150px">
<f:selectItems value="#{countryView.selectedCountry.cities}" itemLabel="#{selectedCity.libelle}" var="selectedCity" itemValue="#{selectedCity}"/>
</p:selectOneMenu>
任何人都可以帮我这么做吗?
答案 0 :(得分:0)
是拉斐尔罗斯我必须这样做:
@OneToMany(fetch = FetchType.EAGER, mappedBy="country", cascade = CascadeType.ALL)
private List<City> cities;
当然我还要添加转换器:
<p:outputLabel for="city" value="City: " />
<p:selectOneMenu id="city" value="#{countryView.selectedCity}" style="width:150px" converter="#{cityConverter}">
<f:selectItems value="#{countryView.selectedCountry.cities}" itemLabel="#{selectedCity.libelle}" var="selectedCity" itemValue="#{selectedCity}"/>
</p:selectOneMenu>
如你所见,我在ajax事件中不需要监听器:
<p:ajax update="city" />