Expand my Community achievements bar.

SOLVED

Best Approach for this scenario

Avatar

Level 4

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

@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

Avatar

Level 4
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.