Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mickleroy/sling-models-sample

Demonstrates the use of Sling Models and PostConstruct in AEM 6.1
https://github.com/mickleroy/sling-models-sample

aem sling-models

Last synced: 10 days ago
JSON representation

Demonstrates the use of Sling Models and PostConstruct in AEM 6.1

Awesome Lists containing this project

README

        

# 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
```

com.github.mickleroy.models

```

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`
```

@PostConstruct was called: ${model.postContructCalled}

```

The component can be drag'n'dropped anywhere (i.e. Geometrixx Outdoors)
![component-result](screenshot.png)

## 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