6 Replies Latest reply on Apr 25, 2007 8:23 AM by sammy8306

    Scoping - finding the sweetspot

    sammy8306

      After fiddling around with long running conversations, experiencing the joy (no detached objects etc.) and aggrevation (when and how to end conversations etc.), I'm now trying to create a sample app in which the pages are as self-sufficient (restful if you will) as possible. When displaying stuff, no problems arise. Put everything in page scope, inject a RequestParameter to indicate what needs to be shown, and prepare everything in an @Create method of a page scoped component.

      However, this breaks when I want to do a JSF postback (for example using an enhanced EL action binding). Now, the RequestParameter will be null and all goes wrong... Is my only option to pass the value of the ReqParam in the enhanced EL binding as well (which seems a bit hackish), or am I missing something? I can post a concrete example if necessary, but I think the point is clear.

        • 1. Re: Scoping - finding the sweetspot

          Use a page action for the restful url.

          Regards

          Felix

          • 2. Re: Scoping - finding the sweetspot
            sammy8306

            Isn't this the same as using a PAGE scoped component en doing the initialization stuff in @Create ? The problem is that a (Seam/JSF) postback action loses all the information from the original url... But may be I'm wrong, could you elaborate a bit?

            • 3. Re: Scoping - finding the sweetspot
              pmuir

              Not quite the same - @Create on a PAGE scoped component will be run when the view is accessed from another view (but not when it is refreshed/reloaded), a page action will be run each time it is accessed/refresed etc.

              As for your original question: I would suggest something like


              private Integer storedId;
              
              @RequestParameter
              private Integer id;
              
              public int getId() {
               if (id !=null) {
               storedId = id;
               }
               return id;
              }


              You'll want to adjust the algorithm a bit so its suits your exact architecture. As your bean is in PAGE scope, storedId will be remembered

              • 4. Re: Scoping - finding the sweetspot
                sammy8306

                Thanks, that looks like a workable solution.

                Another problem I encounter is this: I'm passing an object to a delete action method in the PAGE scoped component. I'm merging this incoming object explicitly with the seam managed entity manager, and then call en.remove() on this object. However, I still get java.lang.IllegalArgumentException: Removing a detached instance org.blog.domainclasses.BlogEntry#1 on this call... shouldn't the merge call guarantee that the object is managed by this em again?

                • 5. Re: Scoping - finding the sweetspot
                  mariuszs

                  you should make somthing like this:

                  em.remove(em.merge(object));

                  • 6. Re: Scoping - finding the sweetspot
                    sammy8306

                    great, thanks!