Hello,
I have a class model where I generate a value for a property from two other
properties, something like that:
@Model(adaptables = Resource.class)
public class MyModel extends AbstractResource implements Resource {
@Inject
private int valueOne;
@Inject
private int valueTwo;
private int sum;
public getSum() {
return sum;
}
@PostConstruct
public void calculateScore() {
sum = valueOne + valueTwo;
}
}
I'd like to see this "sum" property when I call the JSON view:
{
"sling:resourceType": "model/myModel",
"jcr:createdBy": "admin",
"jcr:created": "Mon Dec 07 2015 17:11:31 GMT+0100",
"jcr:primaryType": "sling:Folder",
"valueOne": 10,
"valueTwo": 5,
"sum": 15
}
I tried to save it in a ModifiableValueMap properties that I get with
adaptTo() and display it with new JSONObject(properties) but it requires an
administrative authentication, or now a service with a special user.
I don't mind trying to do that but it seems a bit heavy as a solution, I
was wondering if there would be something easier to do such thing?
Thank you
Guillaume