Passing array generated in js use class to java use class (6.0 to 6.1 upgrade issues) | Community
Skip to main content
Level 4
October 16, 2015
Solved

Passing array generated in js use class to java use class (6.0 to 6.1 upgrade issues)

Upon installing AEM 6.1, the solution to my issue in this thread no longer works: http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manager.topic.html/forum__a0oj-following_uponthis.html.

I get a similar error message as referenced before:

06.06.2015 16:27:28.256 *ERROR* [0:0:0:0:0:0:0:1 [1433622447711] GET /content/news.html HTTP/1.1] com.adobe.cq.sightly.WCMUse Failed to cast value java.lang.ClassCastException: Cannot cast org.apache.sling.scripting.sightly.js.impl.rhino.HybridObject to io.sightly.java.api.Record at java.lang.Class.cast(Class.java:3361) at com.adobe.cq.sightly.WCMUse.get(WCMUse.java:90) at com.uc.news.ArticlesList.activate(ArticlesList.java:42)

 

Lines 39-44 of ArticlesList.java:

public Record params=null;     @Override public void activate() throws Exception { params = get("params", Record.class);

 

I'm unable to find documentation on hybridobject, so I'm again unsure how to proceed.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

You may have found an issue:

" passing the object from the js use file isn't accepted like it was in 6.0."

Please open a ticket here. If there is a bug, they will fix it. Open ticket here: 

https://helpx.adobe.com/marketing-cloud/experience-manager.html

Thank you! 

6 replies

BenSt10Author
Level 4
October 16, 2015

I've attempted to resolve this by changing params to a HybridObject, but I don't think the required packages are available in aem 6.1. Upon trying to include these dependencies in my pom file: 

<dependency> <groupId>org.mozilla</groupId> <artifactId>rhino</artifactId> <version>1.7.6</version> </dependency> <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.scripting.sightly.js.provider</artifactId> <version>1.0.0</version> </dependency> <dependency> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.scripting.sightly</artifactId> <version>1.0.2</version> </dependency>

I get an error. My bundle builds susccesffully, but isn't able to start:

08.06.2015 10:56:52.239 *INFO* [OsgiInstallerImpl] org.apache.sling.installer.core.impl.tasks.BundleStartTask Could not start bundle uc-news.ucNews-bundle [446]. Reason: {}. Will retry. org.osgi.framework.BundleException: Unresolved constraint in bundle uc-news.ucNews-bundle [446]: Unable to resolve 446.19: missing requirement [446.19] osgi.wiring.package; (osgi.wiring.package=org.apache.sling.scripting.sightly.js.impl.rhino)

So this solution seems to be a dead end.

Translate
Feike_Visser1
Employee
October 16, 2015
Feike_Visser1
Employee
October 16, 2015

And can you print the class-name from the object that you are trying to cast?

Translate
BenSt10Author
Level 4
October 16, 2015

When I try  (note I changes Record.class to String.class for this example)

get("params", String.class).getClass().getName();

I get an error:

08.06.2015 14:05:11.428 *ERROR* [0:0:0:0:0:0:0:1 [1433786711362] GET /content/news.html HTTP/1.1] com.adobe.cq.sightly.WCMUse Failed to cast value java.lang.ClassCastException: Cannot cast org.apache.sling.scripting.sightly.js.impl.rhino.HybridObject to java.lang.String

I'm not sure what's going on exactly.

I can pass a string object in my sightly code and it works, but passing the object from the js use file isn't accepted like it was in 6.0.

As an aside, I did change my dependency to the 6.1 case to no avail.

Translate
BenSt10Author
Level 4
October 16, 2015
 

Continuing to troubleshoot this, I think this is a serious issue with 6.1, but I'm hoping I'm just going about this the wrong way, passing the object resolves to null, as far as I can test, but individual data members are not null.

 

My Sightly code:

 

<div data-sly-use.newsList="${'newsList.js' @ props=properties, xssApi=xssApi, page=currentPage}"> ${newsList} <div data-sly-test="${properties.querysearch=='search' && newsList.search=='submitted' || properties.querysearch!='search'}"> <div data-sly-use.articles="${'com.uc.news.ArticlesList' @ params=newsList, limit=newsList.limit}"> ${articles.message} </div> </div> </div>

My Java Use Class:

@Override public void activate() throws Exception { message += "params null " + (get("params", Record.class) == null); message += "--- limit null " + (get("limit", String.class) == null); }

i get this output on the component (the first line is the output of ${newslist}, the second is ${articles.message}):

hasVideo,offset,dateRange,endDate,querysearch,author,sort,articlesExclude,alsoQuery,tags,search,authorExclude,limit,anyall,term,page,articles,contacts,startDate params null true --- limit null false
Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
October 16, 2015

You may have found an issue:

" passing the object from the js use file isn't accepted like it was in 6.0."

Please open a ticket here. If there is a bug, they will fix it. Open ticket here: 

https://helpx.adobe.com/marketing-cloud/experience-manager.html

Thank you! 

Translate