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

data-sly-use - can I link to java and javascript events

Avatar

Avatar
Validate 1
Level 1
dj_datum
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
dj_datum
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
dj_datum
Level 1

03-04-2020

Good Morning,

I am supporting an AEM application with Java 8 backend and javascript supporting the front end. 

One .html page in particular has the data-sly-use pointed to the Java side to autoload a set of combo boxes on page load.  Selection update events are stored in javascript but is not linked to the .html file (yet).  Is it possible to use data-sly-use to point to both the java and javascript sides simultaneously??  

Thank you,

-Daniel 

 

Update: Thank you @BrianKasingli  and @Theo_Pendle Both were solid answers and gave me a lot of good info to investigate.  The error was in the javascript call to the servlet.  The original developer hardcoded the servlet parameter instead of using the parameter being sent to the javascript function.    

data-sly-use

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

613 likes

Total Posts

590 posts

Correct Reply

231 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

613 likes

Total Posts

590 posts

Correct Reply

231 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

04-04-2020

 Selection update events are stored in javascript but are not linked to the .html file (yet).  Is it possible to use data-sly-use to point to both the java and javascript sides simultaneously?

You can achieve this by creating an OSGI Servlet or utilise Apache Sling Model's Jackson JSON exporter. Within the page, JavaScript will make a HTTP GET request to re-render the page, based on your trigger conditions. Your HTML element can have a data-attribute with the servlet endpoint that your component is expected to call.

 

 

<section class="combo-box" data-endpoint="${currentPage.path + 'model.json'}">
 ...
</section>

or

<section class="combo-box" data-endpoint="${currentPage.path + 'customSelector.json'}">
 ...
</section>

 

 

Answers (1)

Answers (1)

Avatar

Avatar
Validate 1
MVP
Theo_Pendle
MVP

Likes

237 likes

Total Posts

251 posts

Correct Reply

105 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 10
Ignite 1
View profile

Avatar
Validate 1
MVP
Theo_Pendle
MVP

Likes

237 likes

Total Posts

251 posts

Correct Reply

105 solutions
Top badges earned
Validate 1
Ignite 5
Ignite 3
Ignite 10
Ignite 1
View profile
Theo_Pendle
MVP

03-04-2020

Hi Daniel, 

From what I understand of your situation, no.

data-sly-use is a backend feature with lets you use either the Java or Javascript Use-API (you can see a comparison of the two here). However, whichever Use-API you decide to go with, they are both executed in the backend, before your HTML file ever arrives in your browser.

If you have JS code that you want to run in your browser, they will have to be part of a clientlib which you load at the same time as your component (usually all clientlibs are loaded at the page level).

Here is an example of where you would place the two different types of JS scripts:

Selection_078.png