3 Replies Latest reply on May 11, 2006 7:29 PM by scottd72

    An excruciatingly simple SEAM question

    scottd72

      OK, I'm clearly missing something key, because I can't get the following extremely simple modification to the extremely simple "registration" example to work, and I've been at it for hours now.

      Suppose all I want to do is add, say, a "debug" String that's set somewhere RegisterAction.register(), and then printed out registered.jsp using an EL expression like "#{debug}". What's the minimal set of changes I'd need to make to the example to make that happen?

      Adding something like "@Out String debug;" to RegisterAction and then "debug = new String("howdy");" in register() doesn't seem to work: attempting to reference "#{debug}" in the jsp silently fails and the reference becomes an empty string in the output, while attempting to reference "#{register.debug}" results in a PropertyNotFoundException. Mucking with the "scope" argument of the @Out annotation doesn't seem to make any difference; neither does changing RegisterAction to @Stateful...

      Why doesn't "#{register.debug}" resolve? (If I neglect to set debug to a non-null value inside register(), I get exceptions complaining about how the register.debug output wasn't set, so clearly the @Out annotation is doing *something*...)

        • 1. Re: An excruciatingly simple SEAM question
          baz

          As far as i know your attempt works right.

          @Out outjects to the context from which the value was injected, or in case of no injection to the surrounding context.

          When you click the register button, you are in a temporary conversation.
          When you outject a value it will go to this temporary conversation.

          After executing the register action, the temporary conversation gets deleted (and with it your value for debug)
          when rendering the registered page, a new temporary conversation is created (with no debug value).


          What changes could you make?
          1. indroduce long running conversations (Set RegisterAction to CONVERSATION Scope and mark register with @Begin)

          2. Create a sessionscoped bean which holds your debug value. Inject and outject debug value

          Ciao,
          Carsten

          • 2. Re: An excruciatingly simple SEAM question
            gavin.king

            (1) The registration example uses a .
            (2) The default scope for @Out is EVENT
            (3) Of course any event-scoped state does not carry across a redirect
            (4) Conversation-scope state does _always_ carry across a redirect (even for temp conversations)

            So just use @Out(scope=ScopeType.CONVERSATION) instead

            • 3. Re: An excruciatingly simple SEAM question
              scottd72

              Actually, no, CONVERSATION doesn't work. I've finally gotten a combination to work, but:
              (1) I need to use "#{debug}", not "#{register.debug}". (Fair enough.)
              (2) I need to use a SESSION scope. If I use CONVERSATION instead,
              then "#{debug}" gets expanded to the empty string instead of the value assigned in register().

              Another unfortunate behavior that confused the heck out of me while I was trying to debug this issue: if I make debug a required output, then if any of the validators fail (because, say, I was only typing in a single-character password), then instead of getting the user-friendly "password must have more characters" warning, the server returns an gnarly error message generated because the debug output wasn't set...the ultimate source of the problem (not enough chars in password) is completely obscured. What's the right way to prevent that from happening, other than just never generating required outputs in any routine that has validated inputs (which sounds like it'd be pretty crippling)?