2 Replies Latest reply on Oct 17, 2012 6:58 AM by steve de rivas

    how to create drop down metadata in which fields are getting populated dynamically?.

    steve de rivas Level 1

      I am creating a metadata of drop down type in which the options are getting populated dynamaiclly. following are the steps which i followed.But the dropdown option is not getting populated . whats the problem?

       

       

      xtype=selection

      type=select

      optionsProvider=path to json file(/apps/dam/content/asseteditors/image/jpeg/formitems/dropdown2/options.json)

      optionsTextField=text

      optionsValueField=value

      optionsRoot=options

       

       

       

       

      in the json file(options.json)

       

       

      "options": [{

      "value": "String",

      "text": "String"

      },

      {

      "value": "Long",

      "text": "Number"

      }]

        • 1. Re: how to create drop down metadata in which fields are getting populated dynamically?.
          kasq Level 3

          Hi,

           

          try to use following configuration for the field in the dialog:

           

          <metadata

              jcr:primaryType="cq:Widget"

              fieldDescription="some description of the field"

              fieldLabel="field label"

              name="./metadata"

              options="/apps/dam/content/asseteditors/image/jpeg/formitems/dropdown2/options.json"

              type="select"

              xtype="selection"/>

           

          and your options.json file should have following structure:

           

          [

            {"value" : "String","text" : "String"},

            {"value" : "Long","text" : "Number"}

          ]

           

          this is way how we populate dropdown list using static json file. Of course json can generated dynamically.

           

          Regards,

          kasq

          • 2. Re: how to create drop down metadata in which fields are getting populated dynamically?.
            steve de rivas Level 1

            if we dynamically create json for example through query builder ,

             

             

             

            <%

            response.setContentType("application/json");

            SlingHttpServletRequest slingReq = (SlingHttpServletRequest) request;

            String strpath = properties.get("path","").toString();

            Session session = slingReq.getResourceResolver().adaptTo(Session.class);

            QueryBuilder builder =

            resource.getResourceResolver().adaptTo(QueryBuilder.class);

            Map<String, String> map = new HashMap<String, String>();

            map.put("type", "cq:Page");

            map.put("path", "/content");

            Query query = builder.createQuery(PredicateGroup.create(map),session);

            result = query.getResult();

            %>

            [<%

             

             

            String delim = "";

            for (Hit hit : result.getHits())

            {

             

             

            %><%= delim %><%

            {

            %>"value":"<%= hit.getPath() %>"<%

            %>"text":"<%= hit.getTitle() %>",<%

            %>"qtip":"",<%

             

             

            %>}<%

            if ("".equals(delim))

            delim = ",";

            }

            %>]

             

             

             

            and the configuration be like

             

            jcr:primaryType="cq:Widget"

                fieldDescription="some description of the field"

                fieldLabel="field label"

                name="./metadata

            xtype=selection

            type=select

            optionsProvider=path to json file(/apps/dam/content/asseteditors/image/jpeg/formitems/dropdown2/options.json)

            optionsTextField=text

            optionsValueField=value

            optionsRoot=hits

            optionsQTipField=qtip

             

            i have done the above step.It is not populating. where i have gone wrong?