Facing issues while passing string array from Sightly to Java WCMUse Class | Community
Skip to main content
New Participant
June 7, 2016
Solved

Facing issues while passing string array from Sightly to Java WCMUse Class

  • June 7, 2016
  • 2 replies
  • 2081 views

Hi All,

In my component.html I have the below :

#1] <div data-sly-use.componentUse="${'com.xxx.xxx.componentUse' @ propertyName='properties.relatedPath'}" data-sly-unwrap>
</div>

where "relatedPath" is of type String[] holding values for the below dialog section

<multi
                        jcr:primaryType="cq:Widget"
                        fieldLabel="Multi-Field"
                        hideLabel="{Boolean}true"
                        name="./relatedPath"
                        xtype="multifield">
                        <fieldConfig
                            jcr:primaryType="nt:unstructured"
                            xtype="pathfield"/>
                    </multi>

#2] In my corresponding Java WCMUse class, I have the below :

private static final String PROPERTY_NAME = "propertyName";

private String[] properties;

public void activate() throws Exception {
        properties = get(PROPERTY_NAME, String[].class);

But "properties" is always returning null, though the property has two values of pathfields.

#3] Also, I see com.adobe.cq.sightly.WCMUse Failed to cast value
java.lang.ClassCastException: Cannot cast java.lang.String to [Ljava.lang.String; getting logged.

Not sure what am I missing. Any thoughts/pointers/reference/snippet will be really helpful.

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 BenSt10

You're passing the literal value 'properties.relatedPath' to the use class, so get(...) is returning that string not the array. Take off the single quotes and it should work:

<div data-sly-use.componentUse="${'com.xxx.xxx.componentUse' @ propertyName=properties.relatedPath}" data-sly-unwrap> </div>

2 replies

kautuk_sahni
Employee
June 8, 2016

Hi 

As mentioned by BEN, Please check the quotes.

You are using:- 

<div data-sly-use.componentUse="${'com.xxx.xxx.componentUse' @ propertyName='properties.relatedPath'}" data-sly-unwrap>

What you should use is:- 

<div data-sly-use.componentUse="${'com.xxx.xxx.componentUse' @ propertyName=properties.relatedPath}" data-sly-unwrap>

 

See this blog post:- http://blogs.adobe.com/experiencedelivers/experience-management/sightly-intro-part-4/

//

<div>
data-sly-use.mycomp="${ 'com.myproject.MyComponent'
@ param1='value1', param2=currentPage}">
${mycomp.calculatedValue}
</div>

Here value1 is actual string passed, but for current page we have used param2=currentPage.

I hope this will help you.

Thanks and Regards

Kautuk Sahni

Kautuk Sahni
BenSt10Accepted solution
New Participant
June 7, 2016

You're passing the literal value 'properties.relatedPath' to the use class, so get(...) is returning that string not the array. Take off the single quotes and it should work:

<div data-sly-use.componentUse="${'com.xxx.xxx.componentUse' @ propertyName=properties.relatedPath}" data-sly-unwrap> </div>