This conversation has been locked due to inactivity. Please create a new post.
This conversation has been locked due to inactivity. Please create a new post.
Hi All,
I have a node called "entries" under the page. The "entries" node having some child nodes like entry1, entry2, entry3. The "entries" and child nodes "entry1" have been creating via code and I don't have any component for this. Now, I'm trying to access the "entries" node in a sling model but it's not working. Below is the screenshot of the node structure,
Below is the code,
@Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
public class HistoryModel {
private static final Logger LOGGER = LoggerFactory.getLogger(HistoryModel.class);
@Self
private Resource currentResource;
/*@ChildResource(name = "entries")
private List<HistoryBean> entries;
*/
@ChildResource(name = "entries")
private Resource entries;
@ChildResource(name="entries",injectionStrategy= InjectionStrategy.OPTIONAL,via = "resource")
Resource child;
public Resource getEntries() {
return entries;
}
public Resource getChild() {
return child;
}
@PostConstruct
protected void postConstruct() {
//Nothing inside
LOGGER.debug("HistoryModel post construct Method().. calling..");
LOGGER.debug("HistoryModel entries.. calling..{}", entries);
LOGGER.debug("HistoryModel child.. calling..{}", child);
}
Tried with @childResource. In the log, I'm getting null. anything wrong in the code? Can anyone help?
@arunpatidar26 @smacdonald2008 @arunpatidar26 @Ratna_Kumar @kautuk_sahni @wimsymons @cqsapientu69896 @vanegi @Veena_Vikram @varuns7990 @Theo_Pendle
Thanks,
Vijay
Solved! Go to Solution.
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
Hi @vijays80591732 ,
If this is not a component and you want to access it in Sling Model, then you can make use of a java class to read its child values and return in Sling Model in this way:
Hi @vijays80591732 ,
If this is not a component and you want to access it in Sling Model, then you can make use of a java class to read its child values and return in Sling Model in this way:
try with
@ChildResource(injectionStrategy = InjectionStrategy.OPTIONAL)
Collection<Resource> entries
Hope this will help
Thanks Suraj for your inputs. I have created a component and calling that from template.html. Now, getting the current resource and fetching the child nodes.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies