0

Hi I have the following:

               <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>

The Ajax call works perfect, but when I try to create the ofer I get the validation error. My converter class:

@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());
        }
    }

I have a table OFER, a table LOCATION and a cross table LOCATION_HAS_OFER, in the above code I want to save an ofer with n locations but I not being able to acces the LOCATION_HAS_OFER Here are is the collection holding the LOCATIONS on my OFER_ENTITY_BEAN

     @ManyToMany(mappedBy = "oferCollection")
      private Collection<Location> locationCollection;

Here is the Relation in the 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;

Best Regards

Equals Method of 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;
}
Ignacio Garat
  • 1,536
  • 6
  • 24
  • 48

0 Answers0