Quantcast
Channel: Adobe Community : Popular Discussions - CQ5 (read only)
Viewing all articles
Browse latest Browse all 12476

Using multi-value properties in JSP components

$
0
0

I am trying to figure out if I am doing some small step wrong or if I don't have a full grasp on how some things work.

 

I am accessing a multi-value property from the JSP of my component:

 

<%@include file="/libs/foundation/global.jsp" %>

    <h2>Keys</h2>

    <div class="container_16">

        <div class="grid_8"><%

Object keysObj = properties.get("keys");

if (keysObj != null)

{

String[] keys = (String[]) keysObj;

%>

<%= keys %><%

} %></div>

</div>

 

Here is how I defined my component:

 

{

     "jcr:createdBy":"admin",

     "jcr:title":"My Listing",

     "allowedParents":["*/*parsys"],

     "componentGroup":"Listing Group",

     "sling:resourceSuperType":"foundation/components/parbase",

     "jcr:created":"Wed Aug 15 2012 20:01:15 GMT-0400",

     "jcr:primaryType":"cq:Component",

     "keys":[""]

}

 

So keys is a multi-value String object. I am supposing the value is a String[].

 

I created a dialog to set the values within the CQ page edit.

 

- myList

--- dialog [cq:Dialog]

----- items [cq:Widget]

------- items [cq:WidgetCollection]

--------- tabs1 [cq:Panel]

----------- items [cq:WidgetCollection]

------------- keys [cq:Widget]

 

The keys cq:Widget is defined as:

 

{

     "fieldLabel":"Keys to List",

     "xtype":"multifield",

     "name":"./keys",

     "jcr:primaryType":"cq:Widget",

     "fieldDescription":"List keys to display"

}

 

I placed the component into an existing geometrixx page to test. When I double-clicked on it I was able to add multiple values.

 

It is failing when I attempt to coerce the properties.get method to a String[]: String[] keys = (String[]) keysObj;

 

16.08.2012 11:58:29.444 *ERROR* [10.176.196.66 [1345132705084] GET /content/geometrixx/en/services.html HTTP/1.1] com.day.cq.wcm.core.impl.WCMDebugFilter Error during include of SlingRequestPathInfo: path='/content/geometrixx/en/services/jcr:content/par/keylist', selectorString='null', extension='html', suffix='null' org.apache.sling.api.scripting.ScriptEvaluationException: An exception occurred processing JSP page /apps/myList/components/keyList/keyList.jsp at line 14

<snip stack trace>

Caused by: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;

 

So all that leads to my question.

 

It looks like I am wrong on how to coerce the results of properties.get to a String[]. What is the best way to work with multi-value properties? I want to iterate through the values in the multi-value property.

 

Should I have specified the index in the method?

---- properties.get("keys[0]");

 

Thanks!


Viewing all articles
Browse latest Browse all 12476

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>