0 Replies Latest reply on Apr 29, 2008 11:10 AM by Comanelea Cristina

    h:selectManyListbox selects a duplicate value

    Comanelea Cristina Newbie

      Hello.


      I've searched on the net, but this bug is not often encountered.


      The context is the following: the user must select a list of zone (areas), and populate a list of strazi (streets) with their corresponding streets.


      <a:region id="zoneRegion">
                              <s:decorate id="zoneDecorate" template="/backend/layout/edit.xhtml" rendered="#{newApartamentInBloc.cerere}">
                                  <ui:define name="label">Zona:</ui:define>
                                  <h:selectManyListbox id="listaZone" value="#{apartamentInBlocCreate.listaZone}" size="6">
                                      <s:selectItems value="#{apartamentInBlocCreate.getZone()}" var="zona" label="#{zona.nume}"/>
                                      <s:convertEntity/>
                                      <a:support id="zonaAjax" event="onblur" ajaxSingle="true" reRender="listaStrazi"/>
                                  </h:selectManyListbox>
                                  <a:status id="statusZona">
                                      <f:facet name="start">
                                          <h:graphicImage value="/img/spinner.gif"/>
                                      </f:facet>
                                  </a:status>
                              </s:decorate>
      </a:region >



      The concerning parts of code from my bean ApartamentInBlocCreate are:


          @ManyToMany(fetch = FetchType.EAGER)
          @JoinTable(name = "APARTAMENTINBLOC_ZONE", joinColumns = @JoinColumn(name = "APARTAMENTINBLOC_ID"), inverseJoinColumns = @JoinColumn(name = "ZONA_ID"))
          @OrderBy("nume asc")
          @Fetch(FetchMode.SUBSELECT)
          private List<Zona> listaZone = new ArrayList<Zona>();
      
          public List<Zona> getListaZone(){
              return listaZone;
          }
      
          public void setListaZone(List<Zona> listaZone){
              this.listaZone = listaZone;
              this.setStrazi(stradaDAO.fillStraziByZone(listaZone));
          }



      and the code for the called method:


        public List<Strada> fillStraziByZone(List<Zona> zone){
              log.info("1 stradaDAO.fillStraziByZone");
              log.info("2 zone size #0", zone.size());
              
              String hql = "from com.brit.apit.realEstate.Strada as o where 1 = 1";
              if (zone.size() >= 1) { // if at least one value was picked
                  hql += " and (";
                  for (Zona obj : zone) {
                      hql += "o.zona.id=" + obj.getId() + " or ";
                  }
                  hql = hql.substring(0, hql.length() - 4);// removing last " or "
                  hql += ") order by o.nume asc";
              }
              Query q = entityManager.createQuery(hql);
              return (List<Strada>)q.getResultList();        
          }



      In fillStraziByZone the zone size is always doubled. If I've selected 3 zone, the log prints that the zone size is 6.
      But when i persist the apartamentInBlocCreate bean, the size  of the listaZone is correct: 3.


      Perhaps it is a view problem?


      Thank you.