Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Best Approach for this scenario

AEMnewbie
Level 4
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
Nikhil-Kumar
Correct answer by
Community Advisor
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
Nikhil-Kumar
Correct answer by
Community Advisor
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

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