Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/mickleroy/sling-models-sample
- Owner: mickleroy
- Created: 2017-01-30T21:54:56.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-30T22:09:18.000Z (almost 8 years ago)
- Last Synced: 2024-10-31T13:17:56.766Z (about 2 months ago)
- Topics: aem, sling-models
- Language: Java
- Size: 23.4 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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