Best Approach for this scenario | Community
Skip to main content
Level 4
August 23, 2020
Solved

Best Approach for this scenario

  • August 23, 2020
  • 1 reply
  • 985 views

I have an image and video dropdown based on which the following field for video or image link is displayed.. I have a requirement to save the value from the selected field to a single property in jcr.

 

i.e If the video was selected the link property should be video link and the next time when the image is selected the link should be updated to image link. 

I have a sling model using which this data is exposed as json and final json should have only one value for the link (image or video) . 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Nikhil-Kumar

@aemnewbie 
First of all if you have two different fields in that case there can't be single property in JCR for both.

I would have done the following thing if I ever got this requirement to implement:
Approach 1:
1. I will get the value selected in Dropdown in sling model. (let's suppose I get seletedValues as image)
2. Based on the value that I get in step 1 I will add that link as part of JSON and Ignore the other one, In this case I will ass the imageUrl as part of JSON.
Same applies for the Video as well.

Approach 2:
Lets suppose you have a single Link field for image and video. In that case save the value with single prop name i.e link.
Then based on the dropdown value update the key value to imagLink or videoLink in JSON taking the value as the link.


Thanks,
Nikhil

1 reply

Nikhil-Kumar
Community Advisor
Nikhil-KumarCommunity AdvisorAccepted solution
Community Advisor
August 23, 2020

@aemnewbie 
First of all if you have two different fields in that case there can't be single property in JCR for both.

I would have done the following thing if I ever got this requirement to implement:
Approach 1:
1. I will get the value selected in Dropdown in sling model. (let's suppose I get seletedValues as image)
2. Based on the value that I get in step 1 I will add that link as part of JSON and Ignore the other one, In this case I will ass the imageUrl as part of JSON.
Same applies for the Video as well.

Approach 2:
Lets suppose you have a single Link field for image and video. In that case save the value with single prop name i.e link.
Then based on the dropdown value update the key value to imagLink or videoLink in JSON taking the value as the link.


Thanks,
Nikhil

AEMnewbieAuthor
Level 4
August 23, 2020
Thanks @nikhil-kumar .. I kind of like the first approach a little cleaner .. And based on the selected drop down value i modified the JSON in the PostConstruct.