2 Replies Latest reply on Apr 10, 2013 4:10 AM by aklimets

    How to set cq:tags property of the code through JCR 2.0

    div_sgh Level 1

      Hi,

      I am trying to set the value of cq:tags programtically through JCR 2.0. When I execute this code

           Session session = repository.login( new SimpleCredentials("admin", "admin".toCharArray()));

                                    Node n12 = session.getNode("/content/testprop_content");

                                    session.getWorkspace().getVersionManager().checkout("/content/testprop_con tent");

                                    Node n1 = session.getNode("/content/testprop_content/jcr:content");

                                    System.out.println("Node n1:"+n1.getName());

                                              n1.addMixin("cq:Taggable");

                                              n1.setProperty("cq:tags", arr);

                                              n1.setProperty("jcr:title","My custom title" );

       

      the value of property jcr:title is set, but cq:tags it is coimg blank , where arr is an array containing 3 values. Am I doing something wrong.

       

      Please let me know how to set the value of property cq:tags through code using jcr 2.0 or jackrabbit apis.

       

       

      Thanks

        • 1. Re: How to set cq:tags property of the code through JCR 2.0
          krzysztof grams Level 1

          Hi,

           

          I've replicated your problem. If tags you have inseretd in your array does not exist in your repository, n1.setProperty("cq:tags", arr) method leaves attribute empty. If you first add tags inside repository n1.setProperty("cq:tags", arr) sets attribute with values in arr.

           

          Hope it's helpful

          • 2. Re: How to set cq:tags property of the code through JCR 2.0
            aklimets Adobe Employee

            The cq:tags property must point to existing tags - otherwise they are ignored and can/will be removed.

             

            You should usually not work with raw cq:tags properties, but use the tagging API.

             

            Citing the docs:

            The implementation of the tagging framework in CQ allows to manage tags and tag content solely by using the JCR API. It ensures that tags set in the cq:tags property are not duplicated, it removes IDs pointing to non-existing tags and updates tag IDs for moved or merged tags. It is done by using a JCR observation listener that reverts any incorrect changes.

            Note that it's not setProperty() itself, but an event listener that removes the invalid references asynchronously, but quickly after the session save().