@Target(value={TYPE,ANNOTATION_TYPE}) @Retention(value=RUNTIME) @Documented public @interface ResourceModel
resources
with
specific sling resource types, JCR primary node types or mixin types.
ResourceModel
are automatically detected by NEBA when their containing packages
are specified in the Neba-packages
bundle manifest header, e.g.
<Neba-Packages> com.acme.app.models, com.acme.app.more.models </Neba-Packages>
When using NEBA with Spring, models can be declared as Spring beans. In this case, NEBA will automatically detect all beans
annotated with ResourceModel
in the application context. Spring beans representing resource models must be prototypically scoped as they represent
dynamically created, contextual pieces of data, not singletons.
adapted to
the corresponding models. This adaptation can also be done automatically using /apps/neba/neba.js
with HTL, DefineObjectsTag
with JSP or the ResourceModelResolver
service.
ResourceModel
are automatically mapped from the properties
of the resource
it represents,
unless they are static, final, injected (annotated with @Inject, @Autowired or @Resource) or
annotated with @Unmapped
. See also @Path
, @This
and @Reference
and refer to the NEBA user guide.
// A resource model for a sling resource type. @ResourceModel
(types = "shared/components/teaser") public class MyTeaser { ... } // A resource model for a JCR node type. @ResourceModel
(types = "nt:base") public class MyBaseModel { ... } // A resource model for a JCR mixin node type. @ResourceModel
(types = "mix:versionable") public class MyVersionableModel { ... }
A ResourceModel
applies to the type hierarchy of a resource.
Therefore, if a Resource
has no
specific ResourceModel
, i.e. no mapping to its
Resource.getResourceType()
or node
type, its sling:resourceType hierarchy, followed by its JCR node type hierarchy (including mixin node types) are
searched for a less specific model.
Adaptable.adaptTo(Class)
public abstract String[] value
resource type
or JCR node type (including mixin types) are acceptable
values for the type mapping. Example: "myapps/components/mycomponent",
"nt:base", "mix:versionable".@Deprecated public abstract String[] types
value()
instead. This method will be removed in future versions of neba.public abstract String name
ResourceModelResolver.resolveMostSpecificModelWithName(Resource, String)
),
thus, decoupling a view from the models type. If not given, the model name is automatically derived from the model's type name.Copyright © 2024. All rights reserved.