Should I use sling model class or implicit properties for my component ? | Community
Skip to main content
Mario248
Level 7
May 29, 2023
Solved

Should I use sling model class or implicit properties for my component ?

  • May 29, 2023
  • 5 replies
  • 2040 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

5 replies

MayurSatav
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 29, 2023

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

 

Kiran_Vedantam
Community Advisor
Community Advisor
May 29, 2023

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.

B_Sravan
Community Advisor
Community Advisor
May 29, 2023

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

rawvarun
Community Advisor
rawvarunCommunity AdvisorAccepted solution
Community Advisor
May 29, 2023
iamnjain
Community Advisor
Community Advisor
May 30, 2023

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.