Best Approach for this scenario



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) . 

Accepted Solutions (1)

Accepted Solutions (1)




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.


Answers (0)