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:
lowerCaseDescription
With parameter
Withparameter Using Template
lowerCaseDescription
Thanks,
Karthi
Solved! Go to Solution.
Views
Replies
Total Likes
Use it in this way...
data-sly-use.extraHelper="${'ExtraHelper' @ text=text}">
mind the quotes around the classname.
Can you check this?
Views
Replies
Total Likes
Use it in this way...
data-sly-use.extraHelper="${'ExtraHelper' @ text=text}">
mind the quotes around the classname.
Can you check this?
Views
Replies
Total Likes
The corresponding documentation page has been updated.
Thanks for having brought this to our attention!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies
Views
Likes
Replies