1 Reply Latest reply on Aug 16, 2012 1:16 PM by Yogesh Upadhyay

    Using multi-value properties in JSP components

    Xavier Beautoir Level 1

      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" %>


          <div class="container_16">

              <div class="grid_8"><%

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

      if (keysObj != null)


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


      <%= keys %><%

      } %></div>



      Here is how I defined my component:




           "jcr:title":"My Listing",


           "componentGroup":"Listing Group",


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





      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",




           "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* [ [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]");