您好我有以下内容:
<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的等于方法
@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;
}