Sightly - Issue while passing parameters to Java Use-Api | Community
Skip to main content
Premkarthic-7WP
October 16, 2015
Solved

Sightly - Issue while passing parameters to Java Use-Api

  • October 16, 2015
  • 2 replies
  • 5231 views

Hi,

 Issue while passing parameters to Java Use-Api

I tried with both the approach (Passing parameters to a use-class upon initialization and Passing parameters from data-sly-template) as mentioned on http://docs.adobe.com/docs/en/aem/6-0/develop/sightly/use-api-in-java.html

In both the cases i am not getting any result.

But If I access the java use api without passing parameters as like <div data-sly-use.info="Info"> its working fine.

Code for reference:

Info.java

package apps.testsightly.components.content.sightlyComponent;

import com.adobe.cq.sightly.WCMUse;

public class Info extends WCMUse {
    private String lowerCaseTitle;
    private String lowerCaseDescription;

    private String reverseText;
  
    @Override
    public void activate() throws Exception {
        lowerCaseTitle = "lowercaseTitle";
        lowerCaseDescription = "lowerCaseDescription";

        String text = get("text", String.class);
        reverseText = new StringBuffer(text).reverse().toString();

 

    }
  
    public String getLowerCaseTitle() {
        return lowerCaseTitle;
    }
  
    public String getLowerCaseDescription() {
        return lowerCaseDescription;
    }

    public String getReverseText()
    {

   return reverseText; 
    }
}

sightlyComponent.html

Test Sightly

 

Without Parameter

<div data-sly-use.info="Info">

  <h1>${info.lowerCaseTitle}</h1>
  <p>${info.lowerCaseDescription}</p>
     

</div>

With parameter    

    <div data-sly-use.info1="${Info @ text='Some text'}">

  <h1>${info1.lowerCaseTitle}</h1>
  <p>${info1.lowerCaseDescription}</p>
  <p>${info1.reverseText}</p>
     

</div>    

Withparameter Using Template

<div data-sly-use.info2="Info"
     data-sly-use.extra="extra.html">
     
  <h1>${info2.lowerCaseTitle}</h1>
  <p>${info2.lowerCaseDescription}</p>
     
  <div data-sly-call="${extra @ text=properties.testfield}"></div>
 
</div>

 

Extra.html

<template data-sly-template.extra="${@ text}"
          data-sly-use.extraHelper="${ExtraHelper @ text=text}">
  <p>${extraHelper.reversedText}</p>
</template>

Extra Helper.java

package apps.testsightly.components.content.sightlyComponent;

import org.apache.sling.api.resource.ModifiableValueMap;

import com.adobe.cq.sightly.WCMUse;

package apps.my_example.components.info;
  
import com.adobe.cq.sightly.WCMUse;
  
public class ExtraHelper extends WCMUse {
    private String reversedText;

     
    @Override
    public void activate() throws Exception {
        String text = get("text", String.class);      
        reversedText = new StringBuilder(text).reverse().toString();


    }
  
    public String getReversedText() {
        return reversedText;
    }
}

 

Output:

lowercaseTitle

lowerCaseDescription

With parameter

 

 

 

Withparameter Using Template

lowercaseTitle

lowerCaseDescription

Thanks,

Karthi

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

Use it in this way...

data-sly-use.extraHelper="${'ExtraHelper' @ text=text}">

 

mind the quotes around the classname.

Can you check this?

2 replies

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

Use it in this way...

data-sly-use.extraHelper="${'ExtraHelper' @ text=text}">

 

mind the quotes around the classname.

Can you check this?

GabrielWalt
Adobe Employee
Adobe Employee
October 16, 2015

The corresponding documentation page has been updated.
Thanks for having brought this to our attention!