I have a component and it has 7 dialog properties and 5 fields are straightforward fields and there is no business logic, 2 fields needs some manipulation. It is return the same way what is authored. I have two options
Case 1 : All 7 fields are simple and return simple string.
Method 1 - Use ${properties.prope1}
Method 2 - Create sling model class and get the property value, like ${myslinemodel.prop1}
Which method is recommended one for Case 1 and why?
Case 2 : only 2 fields needs to have some manipulation and 5 fields return simple return
Method 1 - Use ${properties.prope1} for simple dialog fields and Use ${myslinemodel.prop2} for the backend manipulation
Method 2 - Use ${myslinemodel.prop2} for all 7 fields.
Which method is recommended one for Case 2 and why?
We know both methods works but still wanted to know which method is preferred one.
Solved! Go to Solution.
Hi @Mario248 ,
Please go through this blog it will definitely clear your doubts.
https://www.bounteous.com/insights/2020/07/22/aem-sling-models-why-bother
Hi @Mario248
It's always recommended to separate the business logic from the presentation layer. So, it's always recommended to use sling models to fetch the values from the dialog, even though it's just a getter and setter.
Hope it helps!
Thanks,
Kiran Vedantam.
Sling Models, it is a best practice to use a Sling Model in case of retrieving and performing business logics on the authored values.
-Sravan
Hello @Mario248
I think for case 1 you can use global object properties to access as all are simple string values and no value manipulation required. No need to bother about Sling Model.
For Case 2, If you need to perform some value manipulation ( even if it's minor only ) then it would be recommended to do it at Server Side i.e. Sling Model and return the values.
P.S. I also faced this situation and opted for Sling Model approach.
Views
Like
Replies