Expand my Community achievements bar.

SOLVED

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

Avatar

Level 9

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.

1 Accepted Solution

Avatar

Correct answer by
Level 5

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>

View solution in original post

2 Replies

Avatar

Correct answer by
Level 5

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>

Avatar

Administrator

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