8 Replies Latest reply on Mar 29, 2011 4:49 PM by Rendell Hoffmann Bernardes

    SelectOneMenu Problems

    Rendell Hoffmann Bernardes Newbie

      Can someone help me please?


      I have one selectOneMenu on my page but it is not setting my object




      my xhtml


      <s:decorate id="modSubPrcField" template="../../layout/edit.xhtml">
              <ui:define name="label">#{msgs['label.modelo.subprocesso']}</ui:define>
              <h:selectOneMenu value="#{modeloAtributoControle.modSubPrc}" style="width:150px" required="true">
                      <s:selectItems var="item" value="#{modeloAtributoControle.listaModSubPrc}" label="#{item.nmModSubPrc}" noSelectionLabel="Selecione..."/>
                      <s:convertEntity/>
              </h:selectOneMenu>
      </s:decorate>
      



      and my control


      @SuppressWarnings("serial")
      @Name("modeloAtributoControle")
      @Scope(ScopeType.CONVERSATION)
      public class MantemModeloAtributoControle extends ControleBB<ModAtb, ModeloAtributoBO> {
      
      @In (create = true, required = false)
              private ModSubPrc modSubPrc;
      
      private List<ModSubPrc> listaModSubPrc;
      
      public void setModSubPrc(ModSubPrc modSubPrc) {
                      this.modSubPrc = modSubPrc;
              }
      
              public ModSubPrc getModSubPrc() {
                      return modSubPrc;
              }
      
      public void setListaModSubPrc(List<ModSubPrc> listaModSubPrc) {
           this.listaModSubPrc = listaModSubPrc;
      }
      
      public List<ModSubPrc> getListaModSubPrc() {
           listaModSubPrc = getModSubPrcBo().consultar();//Populate the List with objects ModSubPrc, this part is working
           return listaModSubPrc;
      }
      
      }
      



        • 1. Re: SelectOneMenu Problems
          Monkey Den Master

          A couple things: 


          Is ModSubPrc an @Entity?  If so, be sure there is a hashCode() and equals() method defined, so the converter has a way to compare.


          Also, injecting modSubPrc might be interfering with the value binding of the selectOneMenu.


          A third thing, which is a style matter: I generally only have accessors/mutators for submitted values and outject the lists, for controls like selectOneMenu, to conversation scope.  Cuts a bit of noise from the backing bean.

          • 2. Re: SelectOneMenu Problems
            Rendell Hoffmann Bernardes Newbie

            there is my entity




            /*
             * ModSubPrc.java
             * 
             * Data de criação: 01/03/2011
             *
             * Desenvolvido por C1125600 - Tiago Trindade Stangarlin
             */
             
            package br.com.bb.qgd.entidade;
            
            import java.io.Serializable;
            
            import javax.persistence.GeneratedValue;
            import javax.persistence.GenerationType;
            
            import org.jboss.seam.annotations.Name;
            
            import br.com.bb.entidade.EntidadeBB;
            
            /**
             * <p>Title: ModSubPrc</p>
             * <p>Description: Classe que representa a entidade persistente <code>MOD_SUB_PRC</code>.</p>
             * <br><b>Company:</b> QGD
             * @author C1125600 - Tiago Trindade Stangarlin
             * @version 1.0
             */
            @javax.persistence.Entity
            @javax.persistence.Table(schema="QGD", name = "MOD_SUB_PRC")
            @Name("modSubPrc")
            public class ModSubPrc implements EntidadeBB {
            
                 /** Primary key. */
                 @javax.persistence.Id
                 @GeneratedValue(strategy = GenerationType.IDENTITY)
                 @javax.persistence.Column(name = "CD_MOD_SUB_PRC")
                 private java.lang.Integer id;
            
                 /** Regular field. */
                 @javax.persistence.Column(name = "NM_MOD_SUB_PRC", 
                                                 nullable = false, 
                                                 length = 50, 
                                                 unique = false)
                 private java.lang.String nmModSubPrc;
            
                 @javax.persistence.Column(name = "QT_DD_PZ_PRVT", 
                                                 nullable = false, 
                                                 length = 5, 
                                                 unique = false)
                 private java.lang.Short qtDdPzPrvt;
            
                 /** Association. */
                 @javax.persistence.ManyToOne
                 @javax.persistence.JoinColumns({
                      @javax.persistence.JoinColumn(
                           name = "CD_TIP_MOD_SUB_PRC"          )
                 })
                 private br.com.bb.qgd.entidade.TipModSubPrc tipModSubPrc;
            
                 @javax.persistence.OneToMany(mappedBy = "modSubPrc")
                 private java.util.Set<SubPrc> subPrcs;
            
                 @javax.persistence.OneToMany(mappedBy = "modSubPrc")
                 private java.util.Set<ModAtb> modAtbs;
            
                 @javax.persistence.OneToMany(mappedBy = "modSubPrc")
                 private java.util.Set<ModSubPrcModPrc> modSubPrcModPrcs;
            
                 @javax.persistence.ManyToOne
                 @javax.persistence.JoinColumns({
                      @javax.persistence.JoinColumn(
                           name = "CD_PRFL_ACSS"          )
                 })
                 private br.com.bb.qgd.entidade.PrflAcssTla prflAcssTla;
            
                 /**
                  * @return O valor do atributo id
                  */
                 public java.lang.Integer getId() {
                      return id;
                 }
            
                 /**
                  * @param cdModSubPrc atribui um valor ao atributo id
                  */
                 public void setId(java.lang.Integer cdModSubPrc) {
                      this.id = cdModSubPrc;
                 }
            
                 /**
                  * @return O identificador desta entidade
                  *
                  * @see br.com.politec.alp01.arquitetura.entidade.Entidade#getIdentificador()
                  */
                 public Serializable getIdentificador() {
                      return getId();
                 }
                 
                 /**
                  * @return O valor do atributo nmModSubPrc
                  */
                 public java.lang.String getNmModSubPrc() {
                      return nmModSubPrc;
                 }
            
                 /**
                  * @param _nmModSubPrc atribui um valor 
                  *           ao atributo nmModSubPrc
                  */
                 public void setNmModSubPrc(
                           java.lang.String _nmModSubPrc) {
                      this.nmModSubPrc = _nmModSubPrc;
                 }
                 
                 /**
                  * @return O valor do atributo qtDdPzPrvt
                  */
                 public java.lang.Short getQtDdPzPrvt() {
                      return qtDdPzPrvt;
                 }
            
                 /**
                  * @param _qtDdPzPrvt atribui um valor 
                  *           ao atributo qtDdPzPrvt
                  */
                 public void setQtDdPzPrvt(
                           java.lang.Short _qtDdPzPrvt) {
                      this.qtDdPzPrvt = _qtDdPzPrvt;
                 }
                 
                 /**
                  * @return O valor do atributo tipModSubPrc;
                  */
                 public br.com.bb.qgd.entidade.TipModSubPrc getTipModSubPrc() {
                      if(tipModSubPrc==null){
                           tipModSubPrc = new TipModSubPrc();
                      }
                      return tipModSubPrc;
                 }
            
                 /**
                  * @param _tipModSubPrc atribui um valor 
                  *           ao atributo this.tipModSubPrc
                  */
                 public void setTipModSubPrc(
                           br.com.bb.qgd.entidade.TipModSubPrc _tipModSubPrc) {
                      this.tipModSubPrc = _tipModSubPrc;
                 }
                 
                 /**
                  * @return O valor do atributo subPrcs;
                  */
                 public java.util.Set<SubPrc> getSubPrcs() {
                      return subPrcs;
                 }
            
                 /**
                  * @param _subPrcs atribui um valor 
                  *           ao atributo this.subPrcs
                  */
                 public void setSubPrcs(
                           java.util.Set<SubPrc> _subPrcs) {
                      this.subPrcs = _subPrcs;
                 }
                 
                 /**
                  * @return O valor do atributo modAtbs;
                  */
                 public java.util.Set<ModAtb> getModAtbs() {
                      return modAtbs;
                 }
            
                 /**
                  * @param _modAtbs atribui um valor 
                  *           ao atributo this.modAtbs
                  */
                 public void setModAtbs(
                           java.util.Set<ModAtb> _modAtbs) {
                      this.modAtbs = _modAtbs;
                 }
                 
                 /**
                  * @return O valor do atributo modSubPrcModPrcs;
                  */
                 public java.util.Set<ModSubPrcModPrc> getModSubPrcModPrcs() {
                      return modSubPrcModPrcs;
                 }
            
                 /**
                  * @param _modSubPrcModPrcs atribui um valor 
                  *           ao atributo this.modSubPrcModPrcs
                  */
                 public void setModSubPrcModPrcs(
                           java.util.Set<ModSubPrcModPrc> _modSubPrcModPrcs) {
                      this.modSubPrcModPrcs = _modSubPrcModPrcs;
                 }
                 
                 /**
                  * @return O valor do atributo prflAcssTla;
                  */
                 public br.com.bb.qgd.entidade.PrflAcssTla getPrflAcssTla() {
                      if(prflAcssTla==null){
                           prflAcssTla = new PrflAcssTla();
                      }
                      return prflAcssTla;
                 }
            
                 /**
                  * @param _prflAcssTla atribui um valor 
                  *           ao atributo this.prflAcssTla
                  */
                 public void setPrflAcssTla(
                           br.com.bb.qgd.entidade.PrflAcssTla _prflAcssTla) {
                      this.prflAcssTla = _prflAcssTla;
                 }
                 
                 @Override
                 public int hashCode() {
                      // TODO Auto-generated method stub
                      return super.hashCode();
                 }
                 
                 @Override
                 public boolean equals(Object obj) {
                      // TODO Auto-generated method stub
                      return super.equals(obj);
                 }
                 
            }
             
            
            I don´t use the object ModSubPrc for anything else on this controller
            



            • 3. Re: SelectOneMenu Problems
              Rendell Hoffmann Bernardes Newbie

              I implemented the hashCode and the equals methods but still not working
              and I don´t undestand the second part :/


              what kind of accessors/mutators are u talking about?

              • 4. Re: SelectOneMenu Problems
                Monkey Den Master

                IIRC, you also need to use Seam managed persistence context to get the entity converter to work.  Do you have SMPC configured in components.xml?


                Also, the Object implementations of those methods won't work.  You need to provide an implementation relevant to the entity.

                • 5. Re: SelectOneMenu Problems
                  Monkey Den Master

                  Rendell Hoffmann Bernardes wrote on Mar 29, 2011 13:57:

                  ...
                  what kind of accessors/mutators are u talking about?


                  As I said, that was just style and has no impact on your functionality.

                  • 6. Re: SelectOneMenu Problems
                    Rendell Hoffmann Bernardes Newbie

                    I already have my SMPC configured on my components.xml


                    <persistence:managed-persistence-context
                              name="entityManager" auto-create="false" entity-manager-factory="#{qgdEntityManagerFactory}" />



                    There is a odd thing happening here
                    I have this structure
                    ModAtb
                        - ModSubPrc


                    so I was declaring ModSubPrc and ModAtb
                    after that I was setting


                    getModAtb().setModSubPrc(getModSubPrc());
                    



                    doing like that is not working the xhtml doesen´t set ModSubPrc


                    but if I set directly in the chield Object doin like this on my xtml


                    #{controller.ModAtb.ModSubPrc}
                    



                    works fine


                    do u know whay is that happening?


                    sorry about my english it´s a little better when I speak


                    and thank you for helpping me

                    • 7. Re: SelectOneMenu Problems
                      Monkey Den Master

                      Rendell Hoffmann Bernardes wrote on Mar 29, 2011 13:57:


                      I implemented the hashCode and the equals methods but still not working
                      and I don´t undestand the second part :/



                      1.  The hashCode and equals methods I see above won't suffice.  You need something that uses fields of the entity to determine uniqueness.


                      2.  Where is modSubPrc coming from?  If it comes from the form, you only confuse matters when you inject it here:


                      @In (create = true, required = false)
                      private ModSubPrc modSubPrc;
                      



                      • 8. Re: SelectOneMenu Problems
                        Rendell Hoffmann Bernardes Newbie

                        1.  The hashCode and equals methods I see above won't suffice.  You need something that uses fields of the entity to determine uniqueness.


                        The @Name on the entity isn´t enought to determine uniqueness?



                        2.  Where is modSubPrc coming from?


                        modSubPrc is an atribute of modAtb


                        if I declare value like this


                        #{controller.modAtb.modSubPrc}
                        



                        works fine


                        but if I declare value like this


                        #{controller.modSubPrc}
                        



                        it isn´t work, doesen´t set the object