Sightly-Javascript USE Implemetaion - Question | Community
Skip to main content
Level 3
February 2, 2016
Solved

Sightly-Javascript USE Implemetaion - Question

  • February 2, 2016
  • 4 replies
  • 5499 views

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;
});

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Feike_Visser1

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.

4 replies

smacdonald2008
Level 10
February 2, 2016

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

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
February 2, 2016

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.

edubey
Level 10
February 2, 2016

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

KishCq5Author
Level 3
February 3, 2016

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