Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

Add custom Text Field on creation and store the value of Tag in AEM 6.3 (Touch UI)

Avatar

Level 8

HI,

For tag edit the below links did work

http://www.flexibledesigns.rs/custom-fields-in-tag-dialogs-for-touch-ui/

https://forums.adobe.com/thread/2390213

But I want a custom textfield when submitted the values must  get stored in crxde. Currently i added   new field under body of

/apps/cq/tagging/gui/content/tags/createtag

The field comes up correctly on web browser  but when clicked on submit the custom  name field value is not getting saved on crx de.

Could some provide inputs as how this could be achieved.

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Level 8

I found the solution to it

Added the new property under create tag

Step1:-

/apps/cq/tagging/gui/content/tags/createtag/jcr:content/body/items/form/items/wizard/items/createStep/items/fixedColumns/items/fixedC olumn1/items

<newtextproperty

                                                            granite:class="block"

                                                            granite:id="tagpimid"

                                                            jcr:primaryType="nt:unstructured"

                                                            sling:resourceType="granite/ui/components/coral/foundation/form/textfield"

                                                            fieldLabel="proerty"

                                                            name="newtagproperty"

                                                            required="{Boolean}true"/>

Step2:-

under /apps/cq/tagging/gui/content/tags/createtag/jcr:content/body/items/form

Change the action to new custom servlet

sling:resourceType="granite/ui/components/coral/foundation/form"

                    action="/bin/tagcommandcreateext"

Step3:-

I found that ootb component on dialog creation sends data  servlet /bin/tagcommand  that is com.day.cq.tagging.servlets.TagCommandServlet

so decode and copy this code to your servlet and remove all the unwanted code expect for createtag code

Step4:- under your new servlet which has servlet path with "/bin/tagcommandcreateext" 

private HtmlResponse createTag(TagManager tagManager, SlingHttpServletRequest request){

    ResourceResolver resourceResolver = null;

   Session session = null;

   

    Map<String, Object> subService = new HashMap<>();

            subService.put(ResourceResolverFactory.SUBSERVICE, SUB_SERVICE);

            resourceResolver = resourceResolverFactory.getServiceResourceResolver(subService);

            session = resourceResolver.adaptTo(Session.class);

 

  try {

                Tag tag = tagManager.createTag(tagID, request.getParameter("jcr:title"),

                        request.getParameter("jcr:description"));

               Node tagNode = session.getNode(tag.getPath());

                tagNode.setProperty("newtagproperty",

                  request.getParameter("newtagproperty"));

     session.save();

                return this.createResponse(200, type + " created", tag.getTagID(), tag.getPath());

            }...

View solution in original post

4 Replies

Avatar

Level 5

modify the name and granite:id properly

1794771_pastedImage_0.png

1794772_pastedImage_1.png

then under tagedit.js

1794807_pastedImage_3.png

add the ff:

     var myVariable = res["customField-ID"];
     $("#customField-ID").var(myVariable);

btw, I'm 6.4 but I'm assuming it should work just the same.

Avatar

Level 8

Thanks for the input. But i need the same to work when we use create option for tags

I did the same under but does not work

/apps/cq/tagging/gui/content/tags/createtag/jcr:content/body/items/form/items/wizard/items/createStep/items/fixedColumns/items/fixedColumn1/items

Do you have idea what could be reason??

Avatar

Correct answer by
Level 8

I found the solution to it

Added the new property under create tag

Step1:-

/apps/cq/tagging/gui/content/tags/createtag/jcr:content/body/items/form/items/wizard/items/createStep/items/fixedColumns/items/fixedC olumn1/items

<newtextproperty

                                                            granite:class="block"

                                                            granite:id="tagpimid"

                                                            jcr:primaryType="nt:unstructured"

                                                            sling:resourceType="granite/ui/components/coral/foundation/form/textfield"

                                                            fieldLabel="proerty"

                                                            name="newtagproperty"

                                                            required="{Boolean}true"/>

Step2:-

under /apps/cq/tagging/gui/content/tags/createtag/jcr:content/body/items/form

Change the action to new custom servlet

sling:resourceType="granite/ui/components/coral/foundation/form"

                    action="/bin/tagcommandcreateext"

Step3:-

I found that ootb component on dialog creation sends data  servlet /bin/tagcommand  that is com.day.cq.tagging.servlets.TagCommandServlet

so decode and copy this code to your servlet and remove all the unwanted code expect for createtag code

Step4:- under your new servlet which has servlet path with "/bin/tagcommandcreateext" 

private HtmlResponse createTag(TagManager tagManager, SlingHttpServletRequest request){

    ResourceResolver resourceResolver = null;

   Session session = null;

   

    Map<String, Object> subService = new HashMap<>();

            subService.put(ResourceResolverFactory.SUBSERVICE, SUB_SERVICE);

            resourceResolver = resourceResolverFactory.getServiceResourceResolver(subService);

            session = resourceResolver.adaptTo(Session.class);

 

  try {

                Tag tag = tagManager.createTag(tagID, request.getParameter("jcr:title"),

                        request.getParameter("jcr:description"));

               Node tagNode = session.getNode(tag.getPath());

                tagNode.setProperty("newtagproperty",

                  request.getParameter("newtagproperty"));

     session.save();

                return this.createResponse(200, type + " created", tag.getTagID(), tag.getPath());

            }...