6 Replies Latest reply on Sep 25, 2008 11:54 PM by Francisco Jose Peredo Noguez

    Confused: DataModel annotation: Could it be more intuitive?

    Francisco Jose Peredo Noguez Master

      Hi!


      If I have a code like this:


      @Name("foo"
      public class Foo{
      
      @DataModel
      public List<Bar> getBar(){
      }
      
      }
      
      



      what I expect is that to bind that to show it in a combobox, I have would to write: #{foo.bar} but it turns out I have to write: #{bar}. (Or I am getting it all wrong?)


      Why not add something like:


      @Name("foo"
      public class Foo{
      
      @DataModelPropertyCall
      public List<Bar> getBar(){
      }
      
      }
      
      



      and still wrap the result of getBar, but allow for it to be called #{foo.bar}. (And of course it would not add a context variable to Seam context).


      I just feel it is counter-intuitive for newbies like me that @DataModel just takes something at puts it out of context. Why I can not take advantage of the wrapping without adding the result to Seam context? (Something similar could be done to @DataModelSelection)


      What do you think? (Nobody else gets confused by this? Really?)


        • 1. Re: Confused: DataModel annotation: Could it be more intuitive?
          Pete Muir Master

          Francisco Peredo wrote on Sep 17, 2008 21:58:


          If I have a code like this:

          @Name("foo"
          public class Foo{
          
          @DataModel
          public List<Bar> getBar(){
          }
          
          }
          
          



          what I expect is that to bind that to show it in a combobox, I have would to write: #{foo.bar} but it turns out I have to write: #{bar}. (Or I am getting it all wrong?)



          Correct.



          Why not add something like:

          @Name("foo"
          public class Foo{
          
          @DataModelPropertyCall
          public List<Bar> getBar(){
          }
          
          }
          
          



          and still wrap the result of getBar, but allow for it to be called #{foo.bar}. (And of course it would not add a context variable to Seam context).

          I just feel it is counter-intuitive for newbies like me that @DataModel just takes something at puts it out of context. Why I can not take advantage of the wrapping without adding the result to Seam context? (Something similar could be done to @DataModelSelection)

          What do you think? (Nobody else gets confused by this? Really?)




          If we were starting from scratch today I wouldn't want to include @DataModel in Seam. Just use a List with the <h:dataTable /> and page parameters. So, I'm -1. In fact I would prefer to deprecate the @DataModel stuff.

          • 2. Re: Confused: DataModel annotation: Could it be more intuitive?
            nimo stephan Master

            If we were, to say..



            deprecate the DataModel

            ..then we have to use the JSF Datamodel.


            What about
            @DataModelSelection which interacts with @DataModel ?


            Should we use this:


            @Out
            List <a> out;



            in combination with javax.faces.model.DataModel;


            instead of this:


            @DataModel
            List <a> out;



            What are the pros and cons of using SEAM-DataModel over JSF-Datamodel?


            By the way, when using this:


            @Name("helloSeam")
            class Hello {
            
            ..
            @Factory(value="factory")
            void do(){..
            }
            
            }



            then you say also


            #{factory}



            instead of


            #{helloSeam.factory}




            This is the same with @DataModel!?


            Why we can not say


            #{helloSeam.factory}

            ?


            Indeed, we can say



            #{helloSeam.do}

            , but this is not the same.


            Besides, we can not declare a other factory with the same name factory. It is not possible to say



            #{helloSeam.factory}


            and in another bean



            #{helloSeamAgain.factory}


            as the name of the Factory must be unique.

            • 3. Re: Confused: DataModel annotation: Could it be more intuitive?
              Francisco Jose Peredo Noguez Master

              nimo mayr wrote on Sep 20, 2008 21:35:


              By the way, when using this:

              @Name("helloSeam")
              class Hello {
              
              ..
              @Factory(value="factory")
              void do(){..
              }
              
              }



              then you say also

              #{factory}



              instead of

              #{helloSeam.factory}




              This is the same with @DataModel!?

              Why we can not say

              #{helloSeam.factory}

              ?

              Indeed, we can say


              #{helloSeam.do}

              , but this is not the same.

              Besides, we can not declare a other factory with the same name factory. It is not possible to say


              #{helloSeam.factory}


              and in another bean


              #{helloSeamAgain.factory}


              as the name of the Factory must be unique.


              You read my mind, I was going to post exactly that! I find @Factory almos as confusing as @DataModel, @Factory is to inject an object (or a list of objects) only once something into the seam context so that if the method to produce the is slow, it does not get called many times... but... couldn't we have something like:


              @Name("helloSeam")
              class Hello {
              
              ..
              @GetterCache(ScopeType.PAGE)
              List<SomeEntity> getSomething(){..
              }
              
              }




              So that we can refer to it as #{helloSeam.something} and it runs fast even if getSomething takes a lot to calculate, if we are still in the same page/conversation/session, it returns the value it returned the first time. (Is this doable? Perhaps with some kind of interceptor?)

              • 4. Re: Confused: DataModel annotation: Could it be more intuitive?
                Francisco Jose Peredo Noguez Master

                Pete Muir wrote on Sep 20, 2008 19:00:


                If we were starting from scratch today I wouldn't want to include @DataModel in Seam. Just use a List with the <h:dataTable /> and page parameters. So, I'm -1. In fact I would prefer to deprecate the @DataModel stuff.



                Yes, I feel that way too (I still can not find a good reason to use @DataModel, I always find a way to do things without it), but... as Nimo Mayr wrote: what about those moments when something need to get wrapped by a javax.faces.model.DataModel? (maybe it is not needed very often, but it still is needed)





                • 5. Re: Confused: DataModel annotation: Could it be more intuitive?
                  Alex Savitsky Novice

                  Francisco Peredo wrote on Sep 21, 2008 02:32:

                  ...what about those moments when something need to get wrapped by a javax.faces.model.DataModel? (maybe it is not needed very often, but it still is needed)...


                  Maybe it's just me, but I don't think there's much point to keep a special annotation for something that's only used once in a while? For an infrequent usage, wrapping a list in DataModel manually is perfectly fine to me. So +1 to deprecate the @DataModel stuff.


                  And for @DataModelSelection, one can always code a custom selection action and bind it using JBoss EL extensions (e.g. action="#{bean.select(item)}" where item is what would've been marked as @DataModelSelection). Personally, I've found that I often had to add some extra logic to the selection action, and custom one was easier to modify than the @DataModelSelection. So +1 on deprecationg that one too.