1. Directly printing it using ${properties.value} OR
2. Injecting to Sling Model and using Getter Method of each field to print the value in HTL.
In Second case of numbers of dialog fields increases then number of getter methods and Inject Statements increases.
So just wondering which is the correct and recommended way of rendering simple dialog field values in HTL.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi,
This will also work ${properties.value}
With ${properties.title}, when the HTL are converted into java and it resolve as like below before executing
Object _dynamic_properties = bindings.get("properties"); renderContext.getObjectModel().toString(renderContext.call("xss", renderContext.getObjectModel().resolveProperty(_dynamic_properties, "title")
with sling model Model
_global_myobj = renderContext.call("use", com.myapp.core.models.MyModel.class.getName(), obj()); _global_title = renderContext.getObjectModel().resolveProperty(_global_myobj, "title");
Hi Nikhil, it depends on the use case, but I prefer Sling Model approach over directly using through properties, as with Sling models, you always have the flexibility to expose your model json with anyone. Moreover, you can use Lombok plugin to avoid writing getters and setters by simply using @getter @Setter at class level and you can access them in sightly through your model.
Hope this helps.
Hi,
This will also work ${properties.value}
With ${properties.title}, when the HTL are converted into java and it resolve as like below before executing
Object _dynamic_properties = bindings.get("properties"); renderContext.getObjectModel().toString(renderContext.call("xss", renderContext.getObjectModel().resolveProperty(_dynamic_properties, "title")
with sling model Model
_global_myobj = renderContext.call("use", com.myapp.core.models.MyModel.class.getName(), obj()); _global_title = renderContext.getObjectModel().resolveProperty(_global_myobj, "title");
@Nikhil-Kumar Personally , my thoughts are like below.
I have not seen any recommendation from Adobe which says we should be using Sling Models always. that said, I have been in project where they had made it a mandatory practice to write Sling Model for every component they create. Even a simple text component.
Also , if you go by core components approach/proxy components practice ; a sling model is required.
From what @arunpatidar has mentioned, it is clear that there is not much difference in how the value is compiled to render in the HTL. I would also love to see more expert opinions as I also had this same question always.
Veena ✌
Hi @Nikhil-Kumar ,
As per my knowledge, According to Adobe best practice you should write Sling Models always, even for simple components with very less number of properties.
Hope This helps!!
Thanks
Views
Likes
Replies
Views
Likes
Replies