Tuesday, July 8, 2014

JCR content mapping with Sling Model

follow the easy steps to use sling model for JCR content mapping.

  1. Add sling model bundle dependency information in pom.xml  
  2. Add Sling-Model-Packages declaration in the instruction 
  3. Annotate pojo class with @Model annotation and use @Inject against the fields (with getters)  
  4. Now adapt this pojo with resource.adaptTo() 
  5. This Will map the below content structure easily without the bulgy or cluttered code.  


2 comments:

  1. Interesting ... But does it really help you to get rid of bulky codes? Now you don't have to write code for reading properties anymore that's it.
    What if a resource has children and subchildren (getting created at run time ). Are you going to create bean class for each child resource? How you are going to handle this scenario. Please provide a sample code for that...

    ReplyDelete
    Replies
    1. You can inject the child resources also in the form of list. Accordingly you have to design your model.

      Delete