1 Reply Latest reply on Jul 24, 2011 2:18 PM by David Faulstich

    s:ConvetEntity problem in Seam 2.2.2.Final

    David Faulstich Newbie
      I am getting "value is not valid" when using <h:selectOneMenu + entity + <s:convertEntity.

      My entity has hashCode and equals methods implemented:

      <h:selectOneMenu id="muniUsuario" value="#{usuarioHome.instance.municipio}" required="true">
      <s:selectItems value="#{listaMunicipios}" var="municipioSelecionado" label="#{municipioSelecionado.noMunicipio}" noSelectionLabel=""/>
      <a:support eventsQueue="queueUsuario" event="onchange" bypassUpdates="false" ajaxSingle="true"/>                                                       <s:convertEntity />

      Rendered page:
      <option value="0">Vit&oacute;ria da Conquista</option>

      WHY VALUE IS 0????

      package br.com.infosolo.controle.util;

      import static org.jboss.seam.ScopeType.APPLICATION;

      import java.io.Serializable;
      import java.util.List;

      import javax.persistence.EntityManager;
      import javax.persistence.Query;

      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.Transactional;
      import org.jboss.seam.annotations.Unwrap;

      import br.com.infosolo.snit.entidades.Municipio;

      public class ListaMunicipios implements Serializable {
           private org.jboss.seam.log.Log log;     
           private static final long serialVersionUID = -3902172130442786620L;

           EntityManager em;
           List<Municipio> municipios;

           public List<Municipio> getMunicipios(){
                     Query query = em.createNamedQuery("municipio.retornarTodosMunicipios");
                     municipios = query.getResultList();
                     for(Municipio municipio : municipios){
                          log.info("Municipio carregado: {0} - {1}", municipio.getNuMunicipio(), municipio.getNoMunicipio());
                return municipios;
      I think maybe a problem? This works in seam 2.2.1.Final......
        • 1. Re: s:ConvetEntity problem in Seam 2.2.2.Final
          David Faulstich Newbie
          Hey!!! I Found the error.

          I used Eclipse to implement hashCode and equals methods shortcut.

          The equals method implemented was wrong (maybe hibernate proxy object, i don´t know).

          I changed the method to the following:

               public boolean equals(Object other) {
                    if ((this == other))
                         return true;
                    if ((other == null))
                         return false;
                    if (!(other instanceof Municipio))
                         return false;
                    Municipio castOther = (Municipio) other;
                    if(null != this.getNuMunicipio() && !"".equals(this.getNuMunicipio())){
                         return (this.getNuMunicipio().equals(castOther.getNuMunicipio()));
                         return false;

          And everything is working OK now.