I have a Java model I would like to use in my HTL. It looks something like this:
public class MyModel {
private Model model;
...
public Model getModel() {return model;}
}
public class Model {
private String myField;
...
public String getMyField() {return myField;}
}
I try using it in my template like this:
<sly data-sly-use.myModel="path.to.package.MyModel" />
<div data-sly-use.localModel="${myModel.model}">${localModel.myField}</div>
However when I try editing the page using this model I receive ArrayIndexOutOfBoundException
, no idea where from.
When I try changing data-sly-use
to data-sly-test
there's no exception, the page loads, however the div with the test does not show, so apparently the test returns false.
Does creating such model requires an additional configuration in AEM in order to use it?
The fields in my classes are currently being mocked, so there's no way they are null.
EDIT:
It works when I wrap the Model
object inside MyModel
in a list and use data-sly-list
in the HTL.
data-sly-use
is intended for instantiating Use Objects, not for assigning variables; you should be using data-sly-set instead.
Alternatively, you could just use ${myModel.model.myField}
.