嗨,我有以下内容:
<h:selectOneMenu id="companyID"
value="#{oferController.selected.companyID}"
title="#{bundle.CreateOferTitle_companyID}"
required="true"
requiredMessage="#{bundle.CreateOferRequiredMessage_companyID}">
<f:ajax event="valueChange" execute="companyID" render="locationCollection" />
<f:selectItems value="#{companyController.itemsAvailableSelectOne}"/>
</h:selectOneMenu>
<h:outputLabel value="#{bundle.CreateOferLabel_locationCollection}" for="locationCollection" />
<h:selectManyCheckbox id="locationCollection" value="#{???????????????????????????}" title="#{bundle.CreateOferTitle_locationCollection}">
<f:selectItems value="#{oferController.selected.companyID.locationCollection}"/>
</h:selectManyCheckbox>
Ajax 调用完美,但是当我尝试创建报价时,我收到验证错误。我的转换器类:
@FacesConverter(forClass = Ofer.class)
public static class OferControllerConverter implements Converter {
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
OferController controller = (OferController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "OferController");
return controller.ejbFacade.findOfer(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuffer sb = new StringBuffer();
sb.append(value);
return sb.toString();
}
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof Ofer) {
Ofer o = (Ofer) object;
return getStringKey(o.getIdOfer());
return o.getIdOfer()!= null ? String.valueOf(o.getIdOfer()) : null;
} else {
throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + Ofer.class.getName());
}
}
我有一个表 OFER,一个表 LOCATION 和一个交叉表 LOCATION_HAS_OFER,在上面的代码中,我想保存一个带有 n 个位置的报价,但我无法访问 LOCATION_HAS_OFER 这是在我的 OFER_ENTITY_BEAN 上保存 LOCATIONS 的集合
@ManyToMany(mappedBy = "oferCollection")
private Collection<Location> locationCollection;
这是 LOCATION_ENTITY_BEAN 中的关系
@JoinTable(name = "location_has_ofer", joinColumns = {
@JoinColumn(name = "location_idULocation", referencedColumnName = "idULocation")}, inverseJoinColumns = {
@JoinColumn(name = "ofer_idOfer", referencedColumnName = "idOfer")})
@ManyToMany
private Collection<Ofer> oferCollection;
此致
Ofer.class 的 Equals 方法
@Override
public boolean equals(Object object) {
if (!(object instanceof Ofer)) {
return false;
}
Ofer other = (Ofer) object;
if ((this.idOfer == null && other.idOfer != null) || (this.idOfer != null && !this.idOfer.equals(other.idOfer))) {return false;
}
return true;
}