Hi Justin, thanks a lot. I would like to see a section in the wiki where required injections are described in detail. I guess in case for injected Sling values which are not there the instantiation fails (i.e. adaptTo will return null). What happens in case a default value is specified? In my regard the annotations Optional and Default should not be combined. Regards, Konrad Am 19.12.2013 um 22:33 schrieb Justin Edelson <[email protected]>:
> Hi Konrad, > Defaults have been implemented. Check the wiki. > > Regards, > Justin > > On Thu, Dec 19, 2013 at 12:21 PM, Konrad Windszus <[email protected]> wrote: >> HI Justin, >> thank a lot for that. I am assuming a lot of developers were waiting for >> just that. Could you extend the wiki page with an example on how the model >> bean should then be used from within the view (i.e. the JSP) and also some >> words about the scope of one instance? >> One very good addition to the annotations would probably be a default value >> in case there is nothing reasonable to be injected (very useful for resource >> values which are not yet set). >> Thanks, >> Konrad >> >> Am 19.12.2013 um 18:07 schrieb Justin Edelson <[email protected]>: >> >>> Hi, >>> I've published a page to the wiki about a concept I've been working on >>> to consolidate the various appproaches I have seen in the wild to >>> model object creation. I'm calling this YAMF for now, although ideally >>> we'll just call it Sling Models :) >>> >>> Without repeating the whole contents of the wiki page, at a high >>> level, this is a purely annotation driven approach supporting both >>> classes and interfaces. Your model class simply needs to declare from >>> which other classes it can be adapted: >>> >>> @Model(adaptables=Resource.class) >>> >>> And then annotate the fields (for classes) and methods (for >>> interfaces) which need injection: >>> >>> @Inject >>> private String propertyName; >>> >>> You can inject properties, OSGi services, request attributes, and >>> entries from SlingBindings. >>> >>> New injector types can be created through an SPI. >>> >>> Additional annotations are supported for special cases: >>> >>> @Optional - mark a field/method as optional. >>> @Filter - provide a filter (i.e. for OSGi services) >>> @Named - specify a name (other than the default field/method name) to >>> use for the inejction lookup. >>> >>> More detail can be found here: >>> https://cwiki.apache.org/confluence/display/SLING/YAMF+-+Yet+Another+Model+Factory >>> >>> The working code is up in my whiteboard: >>> https://svn.apache.org/repos/asf/sling/whiteboard/justin/yamf/ >>> >>> Look forward to your feedback. >>> >>> Regards, >>> Justin >>
