9 Replies Latest reply on Aug 18, 2009 1:15 PM by lvdberg

    selectOneMenu Example

    aigleborgne

      Hello,


      I'm beginning with Seam and I've looked at examples but none cover my needs. In an application, you usually have some dropdownlists for references like country, town, ...


      In DvD application example, I found a category dropdownlist, but it is tied to components.xml. Well, I'm trying to do it in a bean. Here is my code:


      JSF :


      <h:selectOneMenu id="selectPays" value="#{individuAction.idpays}">
        <s:selectItems value="#{pays.list}" var="pays" label="#{pays.libpays}"/>  
        <s:convertEntity />  
      </h:selectOneMenu>
      



      Bean:


      @Name("pays")
      @Scope(ScopeType.APPLICATION) 
      public class PaysList implements java.io.Serializable {
           
           private static final long serialVersionUID = -7402234629771271315L;
           
          @In("#{referenceService}")
          protected ReferenceService referenceService;
           
           @Out
           private List<ReferentielpaysBO> list;
       
           @Factory("list")
           public List<ReferentielpaysBO> getList() {
                this.list = referenceService.retrievePays();
                return this.list;
           }
       
           public void setList(List<ReferentielpaysBO> list) {
                this.list = list;
           }
           
      }
      



      I haven't shown referenceService because it is working fine (setting a break point after service call allowed me to control and validate data).
      After resuming execution, I have this error:



      value of context variable is not an instance of the component bound
      to the context variable: pays. If you are using hot deploy, you may
      have attempted to hot deploy a session or application-scoped component 
      definition while using an old instance in the session.
      



      I guess it is due to bad use of annotations. I have troubles understanding some of annotations and documentation is sometimes unclear for a beginner (both in Java and Seam).


      Any idea?

        • 1. Re: selectOneMenu Example
          niox.nikospara.yahoo.com

          Hello,


          The usage of <s:selectItems> seems suspicious:


          The component and the iteration variable both have the same name pays. Could you change the name of one (e.g. the iteration variable) and see what happens, just in case...


          Additionally, you outject the list field of the pays component but access it through pays: #{pays.list}. This is redundant (I suggest you change the select items to: <s:selectItems value="#{list}" .../>).


          Last, from the code it seems that the signature of #{individuAction.idpays} should be:


          public void setIdpays(ReferentielpaysBO x) {...}
          public ReferentielpaysBO getIdpays() {...}
          



          I.e. idpays is a property of type ReferentielpaysBO, same as the list.

          • 2. Re: selectOneMenu Example
            aigleborgne

            Thanks for help. I have changed my code following your instructions but it doesn't work. I have another error through.


            JSF:



            <h:selectOneMenu id="selectPays" value="#{individuAction.idpays}">
            <s:selectItems value="#{listePays}" var="pay" label="#{pay.libpays}"/>  
            <s:convertEntity />  
            </h:selectOneMenu>
            



            Bean:



            @Name("pays")
            @Scope(ScopeType.APPLICATION) 
            public class PaysList implements java.io.Serializable {
                 
                 private static final long serialVersionUID = -7402234629771271315L;
                 
                @In("#{referenceService}")
                protected ReferenceService referenceService;
                 
                 @Out
                 private List<ReferentielpaysBO> listePays;
            
                 @Factory("listePays")
                 public List<ReferentielpaysBO> getListePays() {
                      this.listePays = referenceService.retrievePays();
                      return this.listePays;
                 }
            
                 public void setListePays(List<ReferentielpaysBO> listePays) {
                      this.listePays = listePays;
                 }
                 
            }
            



            I have renamed list to listePays. I guess @Out contexts have to be unique. So listePays is more explicit than list.
            In my JSF, I just refer to listePays as you suggested.


            Relating to stored value, I'll see later. It should print my menu at least (I've tried with some selectItem and it worked.)


            My final goal is to stored selected country into people bean (individuAction). indivduAction is a bean used to view and edit IndividuadresseBO. But I haven't finished this part yet. I'm starting with simple things like oneMenuSelect...


            For information, here is the BO:


            @Entity
            @Table(name = "INDIVIDUADRESSE")
            @NamedQueries({
                 @NamedQuery(
                           name=ALL,
                           query="from IndividuadresseBO")
            })
            @Name("individuadresseBO")
            public class IndividuadresseBO implements java.io.Serializable {
            
                 public class QN{
                      public static final String ALL = "IndividuadresseBO.all";
                 }
                 
               private static final long serialVersionUID = 1L;
            
               @Id
               @Column(name = "IDINDIVIDU" , nullable=false)
               private Long idindividu;
            
            ...
            
            @ManyToOne
               @JoinColumn(name="IDPAYS")
               @ForeignKey(name="FK_INDADRESSE_REFPAYS")
               @Fetch(FetchMode.JOIN)
               private ReferentielpaysBO pays;
            




            • 3. Re: selectOneMenu Example
              aigleborgne

              I forgot to print my new error:




              Could not instantiate Seam component: org.jboss.seam.ui.entityLoader



              In console:



              Can not set static javassist.util.proxy.MethodFilter field org.jboss.seam.ui.JpaEntityLoader_$$_javassist_seam_10._method_filter
               to org.jboss.seam.Component$1





              Can not set static javassist.util.proxy.MethodFilter field org.jboss.seam.ui.JpaEntityLoader_$$_javassist_seam_10._method_filter
               to org.jboss.seam.Component$1






              • 4. Re: selectOneMenu Example
                aigleborgne

                Nobody can help me on this?


                If I could have find somewhere a working example of a selectOneMenu...
                I tried this example : http://maniezhilan.blogspot.com/2008/11/seam-framework-cheat-sheets-2.html
                But it doesn't work!


                • 5. Re: selectOneMenu Example
                  niox.nikospara.yahoo.com

                  Hello again,


                  Have you completed the settings required for <s:convertEntity> in components.xml, as described in ch.32 of the documentation? Could you show the relevant code?


                  Could you show the code of the individuAction component, especially the part related to idpays?

                  • 6. Re: selectOneMenu Example
                    aigleborgne

                    It worked!
                    You was right about s:convertEntity. I have read nowhere that I needed to set components.xml.
                    In fact, Seam is meant to have very little xml configuration... But I admit that I haven't read documentation yet.


                    So, I've just removed convertEntity and it worked immediatly :)


                    A big thank you for your precious help!

                    • 7. Re: selectOneMenu Example
                      aigleborgne
                      I'm still having problems with selectOneMenu.
                      As said in my last post, my list is now working : I can load my page without any error, and the list is working as intended.

                      But if I select something and validate, I get this error:
                      Erreur de conversion quand la valeur com.pndata.pnasso.business.bo.ReferentielpaysBO@2b9789b9 est commise pour le modele null Converter.

                      (in english, something like  Converting error when value ... is commited for model ...

                      I suppose I need to add <s:convertEntity /> to my selectOneMenu but well, I had this error when added:
                      Could not instantiate Seam component: org.jboss.seam.ui.entityLoader

                      I have followed this:
                      http://docs.jboss.org/seam/2.2.0.GA/reference/en-US/html_single/#controls

                      Read many posts relating to this problem, but I can't manage to solve this.

                      My entity manager is declared in my service:
                      @PersistenceContext
                      private EntityManager em;

                      I guess I will use an id instead of object for the value, so no converter are needed...
                      • 8. Re: selectOneMenu Example

                        Have you tried with a new converter? (not s:convertEntity) but a new one special for you type, and then use it this way inside h:selectOneMenu code block:


                        <f:converter  converterId="project.yourConverter"/>
                        


                        And don´t forget to configure it in faces-config.xml




                        • 9. Re: selectOneMenu Example
                          lvdberg

                          Hi Arnaud,


                          Be aware that Seam intercepts stuff with the @In annotation, meaning that a refernce to Entitymanagere annotated with @PersistenceContext is NOT handled by Seam but by the ejb-container.


                          Try changing the anntoation to @In and see if that helps. The convertEntity seam.tag is very usefull if you want direct entityhandling in your pages.