1 Reply Latest reply on Nov 19, 2009 8:29 AM by nickarls

    Model stereotype

    asookazian

      CDI defines one further standard stereotype, @Model, which is expected to be used frequently in web applications:

      @Named
      @RequestScoped
      @Stereotype
      @Target({TYPE, METHOD})
      @Retention(RUNTIME)
      public @interface Model {}




      Instead of using JSF managed beans, just annotate a bean @Model, and use it directly in your JSF view!

      So why can't we just use @Named instead?  Like in Seam, there was no @Model, if an entity class had a @Name it could be referenced directly in a JSF view.


      Also, how was it decided that @Model is @RequestScoped?  Why not @ConversationScoped?  I guess we must create a new stereotype for that...


      And what about hybrid stereotypes?:


      @Named
      @RequestScoped
      @ConversationScoped
      @Stereotype
      @Target({TYPE, METHOD})
      @Retention(RUNTIME)
      public @interface ModelFlexible {}



      so that we must specify via an attribute if we want it to be request or conversation scoped...


      @ModelFlexible(mode=ModeType.CONVERSATION)
      public class MyModel {...}



      but then this perhaps is not type-safe??


      or maybe create two new stereotypes:


      @ModelRequestScoped and @ModelConversationScoped


      or remove the scoping meta-annotation from the annotation and then simply do:


      @Named
      @Stereotype
      @Target({TYPE, METHOD})
      @Retention(RUNTIME)
      public @interface ModelNew {}



      @ModelNew @ConversationScoped
      public class MyFoo {...}

        • 1. Re: Model stereotype
          nickarls

          Well @Named was probably a good fit for...named stuff. It's just a name


          I guess it could have been conversation scoped too (but G didn't want to scare newcomers with the new scope)?


          Stereotypes are merged, they scope has to agree between all merged stereotypes (unless overriden at bean itself)