Skip to content

Demonstrates the use of Sling Models and PostConstruct in AEM 6.1

Notifications You must be signed in to change notification settings

mickleroy/sling-models-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sling Model Test

This application demonstrates the use of Sling Models and the @PostConstruct annotation in AEM 6.1.

The package containing the Sling Model is defined in the maven-bundle-plugin properties

<Sling-Model-Packages>
  com.github.mickleroy.models
</Sling-Model-Packages>

The Sling Model class simply sets a variable to true in the init method annotated with @PostConstruct

@Model(adaptables = Resource.class)
public class SampleModel {
    
    private boolean postContructCalled = false;
    
    @PostConstruct
    public void init() {
        this.postContructCalled = true;
    }

    public boolean isPostContructCalled() {
        return this.postContructCalled;
    }
}

The Sling Model is used in a simple HTL component that outputs the value of postConstructCalled

<sly data-sly-use.model="com.github.mickleroy.models.SampleModel">
	<p>@PostConstruct was called: ${model.postContructCalled}</p>
</sly>

The component can be drag'n'dropped anywhere (i.e. Geometrixx Outdoors) component-result

Building

This project uses Maven for building. Common commands:

From the root directory, run mvn -PautoInstallPackage clean install to build the bundle and content package and install to a CQ instance.

From the bundle directory, run mvn -PautoInstallBundle clean install to build just the bundle and install to a CQ instance.

Specifying CRX Host/Port

The CRX host and port can be specified on the command line with: mvn -Dcrx.host=otherhost -Dcrx.port=5502

About

Demonstrates the use of Sling Models and PostConstruct in AEM 6.1

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published