-
Notifications
You must be signed in to change notification settings - Fork 0
/
SampleModel.kt
36 lines (28 loc) · 1.09 KB
/
SampleModel.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package com.szokone.aem.gokotlin.kotlin.model
import com.szokone.aem.gokotlin.kotlin.service.ConfigurableService
import org.apache.sling.api.resource.Resource
import org.apache.sling.models.annotations.DefaultInjectionStrategy
import org.apache.sling.models.annotations.Model
import javax.annotation.PostConstruct
import javax.inject.Inject
import javax.inject.Named
@Model(adaptables = arrayOf(Resource::class), defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
class SampleModel {
// NOTE: Use this approach when injecting objects like String...
@Inject
lateinit var textfield: String
// NOTE: Use this approach when injecting primitives like Long, Boolean...
@JvmField
@field:[Inject Named("numberfield")]
var numberfield: Long = 0
@JvmField
@field:[Inject Named("checkbox")]
var checkbox: Boolean = false
lateinit var calculatedValue: String
@Inject
lateinit var service: ConfigurableService
@PostConstruct
fun init() {
calculatedValue = "${service.getReplacements()} | ${textfield} | ${numberfield} | ${checkbox}"
}
}