Hi,
1. Can you please recommend the steps to debug the sling model.
2. If I have the method with @PostConstruct, when will it get executed ?
3. If there is a constructor, when will it get executed ?
++++ EXAMPLE ++++
@Model(adaptables=Resource.class)
public class TestModel {
@Inject @Named("path")
private String id;
@Inject @Named("jcr:title")
private String title;
@PostConstruct
protected void init() {
LOG.info("Inside init() ");
}
@Inject
public TestModel(Resource resource) {
final String id = resource.getPath();
}
}
Solved! Go to Solution.
Hi,
Here is a very good Sling model document. I guess you might have gone through if not, please do. Let me know if you have some other question which is not covered in the document. Regarding debugging, Logging could be a good option. I don't know about Eclipse way of debugging. But, people do use eclipse as well.
https://sling.apache.org/documentation/bundles/models.html#postconstruct-methods
----Jitendra
Views
Replies
Total Likes
Hi,
Here is a very good Sling model document. I guess you might have gone through if not, please do. Let me know if you have some other question which is not covered in the document. Regarding debugging, Logging could be a good option. I don't know about Eclipse way of debugging. But, people do use eclipse as well.
https://sling.apache.org/documentation/bundles/models.html#postconstruct-methods
----Jitendra
Views
Replies
Total Likes
Here is one article which shows usage of postconstruct
Sling model works on injection, once all injections are completed this will method (@postconstruct) gets called.
In order to debug you can simply configure slf4j logger in your class and logs can be seen in error.log of your project.
Views
Replies
Total Likes
Thank you for sharing the links. They helped.
Also, I found one more good link with many Model examples:
MODEL EXAMPLES:
Views
Replies
Total Likes
Did you find any better way to debug sling model via eclipse?
Views
Replies
Total Likes
what if you have WCMUSEPOJO working but not the sling models as sling models-->@postconstruct method not at all being called form the HTL component in AEM 6.3 .
Any clue ?
Views
Replies
Total Likes
PostConstruct is only used by sling-models. With WCMUsePojo you have the activate method.
Views
Likes
Replies
Views
Like
Replies