4 Replies Latest reply on Jul 27, 2006 8:04 AM by Ângelo Luis

    Navigating depth in object graph

    Ângelo Luis Newbie

      As always i dont find any example about a true world development...

      String, Integer is nice, but where i have a true persistence object graph with
      something like Client -> Address -> City ->State and so on...


      When a try to save this object graph from a jsf page* i have a javax.faces.el.PropertyNotFoundException: Base is null: ....

      *
      <h:inputText id="addressNumberInput" value="#{cliente.address.number}"/>

      i think that happens because the adddress return null... the Seam, JSF dont instanciates one for me?

      What solution you guys can give to me?

      Thanks very much!!!

      - That why i love ognl null handler of webwork ;-)

        • 1. Re: Navigating depth in object graph
          Pete Muir Master

          How about in your Client Entity

          public class Client {
           private Address address;
           ...
           public Client() {
           address = new Address();
           }
          
           // Getters and Setters
          }


          • 2. Re: Navigating depth in object graph
            Ângelo Luis Newbie

             

            "petemuir" wrote:
            How about in your Client Entity

            public class Client {
             private Address address;
             ...
             public Client() {
             address = new Address();
             }
            
             // Getters and Setters
            }


            OK... but if my address is not required??? when i try to save the client i got a TransientObjectException, something like that!!! :(

            • 3. Re: Navigating depth in object graph
              Pete Muir Master

              If it's not required then set it to null.

              You could also do it in an action method - client.setAddress(new Address()); if you want more control over whether an address is created or not.

              Sorry, my code wasn't complete - you would need a association annotation with at least cascade=PERSIST

              • 4. Re: Navigating depth in object graph
                Ângelo Luis Newbie

                 

                "petemuir" wrote:
                If it's not required then set it to null.

                You could also do it in an action method - client.setAddress(new Address()); if you want more control over whether an address is created or not.

                Sorry, my code wasn't complete - you would need a association annotation with at least cascade=PERSIST


                That is my problem :( , because if i put, for example, my address to null i will have a "javax.faces.el.PropertyNotFoundException: Base is null: bla bla..." if i try to submit something like <h:inputText id="addressNumberInput" value="#{cliente.address.number}"/>...

                My solution is put this in action method like you say, but i have a lot of relationships in the client, with address, sex, etc... i think this give a lot of work and make my code ugly....

                That why i say that ognl null handler thats ww use is cool if getAddress return null he instanciates a new one the time i need, so if no address was typed no address is create, that saomething like that in EL???