5 Replies Latest reply on Jan 19, 2008 4:54 PM by Claudio Grasso

    JSF/Seam Binding and Nested Classes

    Tom Goring Apprentice

      Hi,

      Can anyone explain to me why I can't seem to bind to a nested class.
      As soon as do the outer bean's instance variables are null?

      E.g.

      This is OK:

       <h:selectOneMenu value="#{seamBean.property}">
      ..
       </h:selectOneMenu>
      


      this is Not OK

       <h:selectOneMenu value="#{seamBean.helperObject.property}">
      ..
       </h:selectOneMenu>
      


      helperObject in this case would be a simple class that derived some fields from the seamBean.
      E.g. (code just for illustration)
      HelperObject getHelperObject() {
       return new HelperObject() {
       public String getProperty() {
       return parent.property;
       }
      }
      


      When getProperty is invoked here all the SeamBean's instance variables are null (when they are in fact populated). Also the toString on the seamBean is showing the same Java instance ... so I can't understand why it's state is different.

      Are there some rules about binding properties in JSF or Seam?

      Thanks in advance....




        • 1. Re: JSF/Seam Binding and Nested Classes
          Matt Drees Master

          Are the "instance variables" you speak of annotated @In?

          Also, maybe you could clarify what "parent" is. Is it one of the instance variables you're talking about?

          • 2. Re: JSF/Seam Binding and Nested Classes
            Claudio Grasso Newbie

            Could you find the answer? I am stuck with the same problem.
            Just in case the problem is not clear:

            @Stateful
            @Entity
            @Name("mother")
            public class Mother {
            
             private Daughter daughter;
            
             ... setters and getters
            }
            
            


            and the nested class is:

            public class Daughter {
            
             private String someprop;
            
             ... setters and getters
            
            }
            
            


            When I try to put something in daughters property someprop

             <h:inputText value="#{mother.daughter.someprop}"/>
            


            the contents of the html field are not transfered to someprop and any action invoked from the page is not even executed. It seems that the lifecycle ends when the framework tries to transfer values from the request to the properties inside the object inside the EJB.
            I am using seam 1.2.1 and quite desperated.
            Thaks in advance.

            • 3. Re: JSF/Seam Binding and Nested Classes
              Claudio Grasso Newbie

              In the first code snippet please ignore the annotation @Stateful. It is just a typo (it s not in my code). My code is just:

              @Entity
              @Name("mother")
              public class Mother {
              
               private Daughter daughter;
              
               ... setters and getters
              }
              


              I found a workaround defining Daughter as a Seam component:

              @Name("daughter")
              public class Daughter {
              
               private String someprop;
              
               ... setters and getters
              
              }
              



              and then using it as a separate component and asociating it with mother in Java:

              I mean instad of using:

               <h:inputText value="#{mother.daughter.someprop}"/>
              


              I use:

               <h:inputText value="#{daughter.someprop}"/>
              


              and then in the action bean:

              
              @Stateful
              public class ActionBean {
               ....
              
               @In
               private Mother mother;
              
               @In
               private Daughter daughter;
              
               public void persistMother () {
              
               mother.setDaughter(daughter);
              
               em.persist (daughter);
              
               }
              
               ....
              }
              


              It is not elegant but at least it works.

              Nevertheless I would like to know if there is any bug in the Expression Language interpreter or if I am doing something wrong. Accortding to JSF specification the first sintax I mention should work.

              any comments?

              Thanks in advnace.

              • 4. Re: JSF/Seam Binding and Nested Classes
                Matt Drees Master

                Do you ever create a Daughter object?

                I think you may need to post more code, and details on what fails. It looks like what you are trying to do should work, but it's not completely clear from what you've posted so far.

                • 5. Re: JSF/Seam Binding and Nested Classes
                  Claudio Grasso Newbie

                  You are ABSOLUTELY RIGHT. I am never creating daughter, I have just a reference. My code should be:

                  @Entity
                  @Name("mother")
                  public class Mother {
                  
                   private Daughter daughter = new Daughter();
                  
                   ... setters and getters
                  }
                  


                  When poor old Seam tried to set the values for daugher it found no target object.

                  Thank you very very much.