Expand my Community achievements bar.

SOLVED

Sightly-Javascript USE Implemetaion - Question

Avatar

Level 3

Hi All,

i am new to sightly.i understand that javascript USE class will be an server side programming. is there any way we can call an function written in javascript use file from sightly template? below is code which i  am trying to but the call is not getting executed onclick. let me know how to achieve this kind of scenario

HTML:

<div data-sly-use.model="logic.js">
<button id="clear-completed" onclick="${model.addItemAction}"> Click
    </button></div>

logic.js

use('/apps/todo/components/utils/filters.js', function (filters){
'use strict';

    var model = filters;
     function addItemAction() {
        log.info("11111111111111111111111111111111111111111111111");
    }
    model.addItemAction = addItemAction();
    return model;
});

1 Accepted Solution

Avatar

Correct answer by
Employee

Sightly is *only* server-side. So the onclick() here will never work.

I don't fully agree with Scott's comment on Java/OSGi. Both work well, and depends on your experience and other design considerations.

View solution in original post

4 Replies

Avatar

Level 10

For server side execution of app logic with Sightly - you can use Java and OSGi (modified based on Feike comments)

 The Java class extends com.adobe.cq.sightly.WCMUse. 

Using Java and Sightly - see this article: 

https://helpx.adobe.com/experience-manager/using/creating-sightly-component.html

Avatar

Correct answer by
Employee

Sightly is *only* server-side. So the onclick() here will never work.

I don't fully agree with Scott's comment on Java/OSGi. Both work well, and depends on your experience and other design considerations.

Avatar

Level 10

As @feike mentioned you will not be able to JS like code as sightly is server side.

It would be great if you can share your use case may be community can tell better approach

Avatar

Level 3

Thanks a lot for the replies. Now i understood why it wont work which i tried.

I have an scenario. can you please let me know how we can implement

1. There is an HTML form in sightly

2. once submit data has to be pushed to Servlet  (as we cant invoke function in javascript use class i have wriiten an ajax call in another js file)

3. we need to send the inputs to service which gives an additional details (calling the OSGI service in servlet and getting additional data)

4.  the additional details has to be passed to another sighlty page and display the same in UI (how to do this from servlet ????)