Hi Guillaume,

There is no direct relationship between these models and the sling resource 
type. You can look at these models as views on arbitrary resources. Indeed, you 
can obtain an instance of a model by adapting to it from an arbitrary resource, 
for instance:

Resource documentResource = resourceResolver.getResource("/path/to/document");
Document document = documentResource.adaptTo(Document.class)

Note, however, that these models are read-only, i.e. there is currently no 
support to persist them*.

However, whether you require structured data (specific node types) or 
unstructured data, sling models or anything else really depends on you use 
cases. For many cases, storing the data with suitable sling:resourceTypes and 
rendering it on demand (e.g. using Sightly) is completely sufficient. 

Sling differs from other web frameworks in that it does not restrict you to one 
specific way in which to deal with things, but offers a very vast amount of 
options. In other words: What is your use case? For instance, what is the 
semantic structure of your data, who shall be using it and what for, how does 
it change / update, what data volume do you expect etc. Following, I'd then 
look at how these semantics are best expressed in a RESTful architectural style 
(which is the core concept of Sling). 

I'd address the implementation details last, since - contrary to many other web 
frameworks - those do not dominate the solution design.

Regards,
Olaf

* Okay, there is JCR OCM, but it's dated / requires some additional work: 
http://www.connectcon.ch/2015/en/speakers/katarzyna-kozlowska.html
 

-----Original Message-----
From: Guillaume Lucazeau [mailto:glucaz...@gmail.com] 
Sent: Freitag, 13. November 2015 16:10
To: users@sling.apache.org
Subject: Re: Resource class vs CND

Thank you for your advice

I got rid of my CND file and created content using sling:resourceType. I had 
the idea that defining my node structure somewhere would allow me to create 
form dynamically to add subnodes.

So I've created two classes:
// Document.java
@Model(adaptables=Resource.class)
public class Document {

  @Inject @Named("jcr:title")
  private String title;

  @Inject
  private List<Resource> pages;
}

// Page.java
@Model(adaptables=Resource.class)
public class Page {

  @Inject @Named("jcr:title")
  private String title;

  @Inject
  private List<Resource> components;
}

But I don't see how to map them to a sling:resourceType. Is it with
getResourceType() like in here:
https://svn.apache.org/repos/asf/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/resourceprovider/PlanetResource.java
?

Sling definitely has its own rhythm to it and I'm slow to pick it up :)



On Fri, Nov 13, 2015 at 2:48 PM, Daniel Klco <daniel.k...@gmail.com> wrote:

> Agreed, I would also highly suggest looking at Sling Models as an 
> option to make your code more strongly typed without requiring a rigid 
> node type
> structure:
> https://sling.apache.org/documentation/bundles/models.html
>
> On Fri, Nov 13, 2015 at 8:37 AM, Jason Bailey <jason.bai...@sas.com>
> wrote:
>
> > My opinions:
> >
> > Sling is really about being able to take a data set and present that 
> > data in multiple ways. For the vast majority of use cases you should 
> > use the existing node types and property values and you don't need to  use 
> > a CND.
> >
> > A custom nodetype is useful if there is a need to perform some 
> > explicit searching over a large set of data or if you absolutely 
> > require
> limitations
> > on properties that the existing nodetypes don't help with.
> >
> > Avoid trying to think of it in terms of other frameworks; Sling has 
> > its own rhythm to it. You have a request that identifies a resource 
> > and then that data is handed off to a renderer.  Using as much out 
> > of the box functionality will give you the greatest flexibility.
> >
> >
> > -Jason
> >
> > -----Original Message-----
> > From: Guillaume Lucazeau [mailto:glucaz...@gmail.com]
> > Sent: Friday, November 13, 2015 8:01 AM
> > To: users@sling.apache.org
> > Subject: Resource class vs CND
> >
> > Hello,
> >
> > I'm currently studying Sling for a project, to store "documents"
> > containing pages, and components (image, text, maps, graphs etc.)
> >
> > While it seems to fit our needs perfectly, I'm a bit struggling to 
> > learn some basic stuff before presenting a POC to our team.
> >
> > My first question would be: on what criteria should I choose to 
> > manage my resources using a class extending AbstractResource or a 
> > nodetype
> definition
> > in a CND file? Do you have advice on it? I'm tending to use a class 
> > to
> keep
> > everything in Java, but I'm wondering if it's more/less/equally 
> > flexible, and if it has drawbacks or benefits compared to a CND file.
> >
> > Thank you for every information you could give me
> >
> > Regards,
> > Guillaume
> >
>

Reply via email to