Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

It is especially useful for development of complex components, composed of another components - you can then easily reuse models of your simple components. Picture below presents an example:

ChildrenFieldProcessor

ChildrenFieldProcessor maps fields of type java.util.List which are annotated by com.cognifide.slice.mapper.annotation.Children. It reads all children of a resource indicated by @JcrProperty and maps them into a list of models. This allows you to easily go down into tree hierarchy and map child resources into list of mapped models.

Code Block
@SliceResource
public class ComplexTextModel {

    @Children(LinkModel.class)
    @JcrProperty
    private List<LinkModel> links;
    
    //...
}

@SliceResource
public class LinkModel {
    @JcrProperty
    private String path;

    //...
}

 

SliceReferenceProcessor

It processes fields which are annotated with com.cognifide.slice.mapper.annotation.SliceReference. It allows for mapping of models from a different resource (path) than a current resource

The @SliceReference annotation takes a path as a value. The value can be either an absolute path (like /content/test/home/jcr:content/par) or child path (like childResource/grandChildResource) - then it will be resolved relatively to current resource. Bear in mind that parent resources (like ../../test) are not supported.

The value of a path can contain placeholders in form of: ${placeholderName}. This can be useful when the path is dynamic and changes depending on request, e.g. contains language. Instead of hardcoding the language in the path (like: /content/site/en/home), you can put placeholder and have this path to be dynamically evaluated, e.g. /content/site/${language}/home.

...