10 Replies Latest reply on Aug 28, 2007 9:48 AM by fhh

    Seam 2.0: Why does @Datamodel require a setter?

      Hello!

      This patch http://lists.jboss.org/pipermail/jboss-cvs-commits/2007-August/039852.html
      requires all methods annotated with @Datamodels to have a corresponding setter.

      This makes the Seam 2.0 migration much harder than necessary. My project has lots of lists that are created on the fly when the get-Method is called. So these are really readonly. Seam 2.0 will require to add empty setters to all these components.

      Is this change of behaviour intended?

      Regards

      Felix

      P.S.: Does anybody know why deployment exceptions are swalloed?

        • 1. Re: Seam 2.0: Why does @Datamodel require a setter?

          bump

          • 2. Re: Seam 2.0: Why does @Datamodel require a setter?
            pmuir

            If you file a JIRA issue I can move the check for the setter to later on (you will still need a setter for the DataModel if you are using @DataModelSelection though)

            • 3. Re: Seam 2.0: Why does @Datamodel require a setter?

              Done.

              http://jira.jboss.com/jira/browse/JBSEAM-1868


              IMHO a setter should not even be required when susing @DataModelSelection. The datamodel should be available from the context it was outjected to. Pre Seam 2.0 this was not required so this is a clear regression to me. On the other hand adding emty setters is not that hard...


              Regards

              Felix

              • 4. Re: Seam 2.0: Why does @Datamodel require a setter?
                pmuir

                It's required if the DataModel has been outjected to PAGE scope (as the component is event scoped but the datamodel isn't). I'll drastically reduce the requirement for the setter by only calling when we are using PAGE scope :) (n.b. previous to this change you would have got an IAE if you fall into the small group of programs who were doing this).

                • 5. Re: Seam 2.0: Why does @Datamodel require a setter?

                  Maybe I am a bit thick here but I still don't get why a setter should be needed. If the datamodel is page scoped I would expect it to go back into page context (= Contexts.getPageContext().set("name", dataModel)) after deserialization. What sense does it make to reinject it into the action bean even if that particular action bean is not called in a second request.

                  I always thought that @DataModel works pretty much like @Factory: Once a datamodel is created it becomes a completly independent, fist-class component. The difference is of course that @Factory is called automatically and @DataModel is only used if the annotated bean is called.

                  Regards

                  Felix

                  • 6. Re: Seam 2.0: Why does @Datamodel require a setter?
                    pmuir

                    So that when you do:

                    @Name("eventLister")
                    public class EventListerAction {
                    
                     @DataModel(value="eventList", scope=ScopeType.PAGE)
                     private List<Integer> eventList;
                    
                     @DataModelSelection("eventList")
                     private Integer selectedEvent;
                    
                     @Factory("eventList")
                     public void initRequestList() {
                     ...
                     }
                    
                     public void selectEvent() {
                     log.info(selectedEvent);
                     }
                    
                    }


                    That eventList isn't null (it would be unless we did this set). This seems like a reasonable assumption to me (and anyway we can't change this behaviour now!). This is the relevant commit:

                    http://fisheye.jboss.com/browse/JBoss/jboss-seam/src/main/org/jboss/seam/Component.java?r=1.93#l734

                    I always thought that @DataModel works pretty much like @Factory: Once a datamodel is created it becomes a completly independent, fist-class component. The difference is of course that @Factory is called automatically and @DataModel is only used if the annotated bean is called.


                    @DataModel is like @Out with additional logic to "convert" the data from one type to another (e.g. List -> DataModel). However it has an additional bit (reinjecting the value when using PAGE scope) - that which we are discussing.

                    I've committed a fix to CVS, let me know how it works out.

                    • 7. Re: Seam 2.0: Why does @Datamodel require a setter?
                      christian.bauer

                       

                      @DataModel is like @Out with additional logic to "convert" the data from one type to another (e.g. List -> DataModel). However it has an additional bit (reinjecting the value when using PAGE scope) - that which we are discussing.


                      Add this explanation and the discussion result to the docs, please.


                      • 8. Re: Seam 2.0: Why does @Datamodel require a setter?

                        I think I am finally getting you. IMHO it is acceptable that the backing list would be null during the second call but than null would be outjected again and the dataModel removed from its scope after the call which is probably a bit confusing :-).

                        But if this is correct doesn't this problem apply to any case where the scope of the datamodel is longer than that of the action bean outjecting it? The same could happen with a stateless action bean and a conversation scoped datamodel.

                        Regards

                        Felix

                        • 9. Re: Seam 2.0: Why does @Datamodel require a setter?
                          pmuir

                           

                          But if this is correct doesn't this problem apply to any case where the scope of the datamodel is longer than that of the action bean outjecting it? The same could happen with a stateless action bean and a conversation scoped datamodel.


                          No because the only scope you can specify on @DataModel is PAGE (otherwise it is UNSPECIFIED aka same as the containing component).

                          I will write this up for the manual.

                          • 10. Re: Seam 2.0: Why does @Datamodel require a setter?

                            Okay. Thanks for the comprehensive information!

                            Regards

                            Felix