Solved
No text available
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
The injected fields are normally the properties of a component (which the content authors normally set via component dialog).
@586265:
@Model(adaptables=Resource.class)
public class MyModel {
@Inject
private String propertyName;
}
In this case, a property named "propertyName" will be looked up from the Resource (after first adapting it to a ValueMap) and it is injected.
Avoid @Inject. Value injection happens at runtime. If you use @586265 then you are making the framework do extra guesswork. It would be good if we use injector annotations like @ValueMapValue, @childResource
Value Map (name=”valuemap”) Injector
Gets a property from a ValueMap by name; If @2434638 is not set, it will automatically take resource if the adaptable is the SlingHttpServletRequest. If name is not set the name is derived from the method/field name.
@Model(adaptables = SlingHttpServletRequest.class,
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class ExampleComponent {
// @Inject @Source("valuemap") @Named("jcr:title")
@ValueMapValue(name = "jcr:title")
private String titleText;
// @Inject @Source("valuemap")
@ValueMapValue
private String titleDescription;
It means if we use @@ValueMapValue it will be done automatically an we have to write less code.
Refer here-https://sling.apache.org/documentation/bundles/models.html
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.