3 Replies Latest reply on Nov 23, 2006 7:13 AM by pmuir

    [booking example]: question regarding the HotelBookingAction

    ellenzhao

      The code in question:

      @In(required=false)
      @Out(required=false)
      private Booking booking;
      
      


      I thought a booking without a Booking instance sounds weird, so that I removed the (required=false) for the @In annotation. But then got an org.jboss.seam.RequiredException. But in the RegisterAction.java, there is

      @In
      private User user;
      


      And it works. I looked for the more precise explanation about the "required" attribute, but the documentation didn't answer my question: Required from what? Required for what? (I thought a Booking instance should be required for a booking action, logically. But it seems that it is "required" from the context.... I changed the annotation to @In (create = true) and it worked again, but I guess the created instance would soon be an orphan in the heap since there is this line:
      booking = new Booking(hotel, user);
      


      in the bookHotel() method. )

      More changes I made to the code: after user login, the pageflow is managed by a jpdl file.

        • 1. Re: [booking example]: question regarding the HotelBookingAc
          pmuir

          The required attribute on @In/@Out simply says whether the variable can be null or not, by default required=true.

          so, lets say we have a variable foo.

          If the context variable foo is null

          @In Foo foo;


          would throw a RequiredException

          but

          @In(required=true) Foo foo;


          wouldn't.

          But, if the context variable foo is not null

          neither

          @In Foo foo;


          nor

          @In(required=true) Foo foo;


          would throw a RequiredException.

          If you are using out, its the instance variable, not the context variable that is not null.

          If create=true then, if the context variable is null, Seam attempts to create it (@Name or @Factory), if it can't, and required=true, then a RequiredException will be thrown.


          • 2. Re: [booking example]: question regarding the HotelBookingAc
            ellenzhao

             

            "petemuir" wrote:
            The required attribute on @In/@Out simply says whether the variable can be null or not, by default required=true.

            so, lets say we have a variable foo.

            If the context variable foo is null

            @In Foo foo;


            would throw a RequiredException

            but

            @In(required=true) Foo foo;


            wouldn't.



            Was there a typo? It might be
            @In(required = false) Foo foo;

            or?


            • 3. Re: [booking example]: question regarding the HotelBookingAc
              pmuir

              Sorry, yes, a typo ;)