13 Replies Latest reply on Apr 17, 2013 3:26 AM by aslkit

    How can I add a custom attribute to the create page dialog?

    aslkit

      I followed the following link to add a custom attribute called starred and this attaribute can be displayed in siteadmin grid

       

       

      http://dev.day.com/docs/en/cq/current/developing/customize_siteadmin.html

       

       

      I would like to let the user input the value when they create a page. That's why I would like to add a custom field in the input dialog box as attached pic.

       

       

      The method you describe before can only added those CQ bulid-in attribute.

       

       

      For those custom attribute, how can I added it?1.png

        • 1. Re: How can I add a custom attribute to the create page dialog?
          dcollie Adobe Employee

          Hi aslkit,

           

          You can customize the UI by overlaying the following script into apps [1] and adding your Widget item into the createDialog.   The issue comes when storing that node, as the builtin CreatePageCommand only processes the title, name and template attributes.   

           

          One method I guess you could create a custom WCMCommand [2] and make the createDialog to submit to it (you would need to build the persisting logic yourself using [3]).   I haven't tried this part,

           

          [1] /libs/cq/ui/widgets/source/widgets/wcm/Page.Actions.js

          [2] http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/api/commands/WCMCommand.html

          [3] http://dev.day.com/docs/en/cq/current/javadoc/com/day/cq/wcm/api/PageManager.html#create(j ava.lang.String, java.lang.String, java.lang.String, java.lang.String)

           

          Cheers -- David

          • 2. Re: How can I add a custom attribute to the create page dialog?
            aslkit Level 1

            Hi,

             

            How can I customize the /bin/wcmcommand or how can I make use of [2] to create a custom WCMCommand?

             

            I think the "formUrl" is to post those input value to the jcr repository?

             

            var createDialog = {

                    "jcr:primaryType": "cq:Dialog",

                    "id": CQ.Util.createId("cq-createdialog"),

                    "title":CQ.I18n.getMessage("Create Page"),

                    "formUrl": CQ.shared.HTTP.externalize("/bin/wcmcommand"),

                    "params": {

                        "cmd":"createPage",

                        "_charset_":"utf-8"

                    },

             

            I have added a field called "starred"

             

            a1.png

             

            Moreover, when I using the firebug to trace the post command, I can see that the starred value is posted also.

             

            :statusbrowser
            _charset_utf-8
            cmdcreatePage
            labelb
            parentPath/content/keyword_elaboration
            starredc
            template/libs/collab/commons/templates/form
            titlea

            Source

            cmd=createPage&_charset_=utf-8&%3Astatus=browser&parentPath=%2Fcontent%2Fkeyword_elaboration&title=a&label=b&starred=c&template=%2Flibs%2Fcollab%2Fcommons%2Ftemplates%2Fform

             

            However, when I go to the crxde to view the node's attribute, the properity starred is not created

            a11.png

             

            Are there anything I did wrong or missing?

             

            Thanks.

             

            Message was edited by: aslkit

            • 3. Re: How can I add a custom attribute to the create page dialog?
              dcollie Adobe Employee

              Hi aslkit,

               

              You are still targeting the "createPage" command in your UI, you would need to change the "params > cmd" value to target a new WCMCommand.

               

              Then need to code an implementation of WCMCommand in a custom bundle deployed to CQ that answered your new value for "params > cmd" for getCommandName().

               

              Cheers -- David

              • 4. Re: How can I add a custom attribute to the create page dialog?
                aslkit Level 1

                How can I implement a new WCMCommand and how can I reference the CQ default WCMCommand?

                • 5. Re: How can I add a custom attribute to the create page dialog?
                  dcollie Adobe Employee

                  You need to write a custom Java class that implements the WCMCommand Interface as well as defining itself as a @Service/@Component and returns a unique value that you define for getCommandName().   You then deploy that to CQ and the WCMCommandServlet will register it with itself.   By changing the UI for "params > cmd" you can then make your form call this new custom WCMCommand.

                   

                  You cannot reference the default WCMCommand, it is hard coded to only process the title/name/template properties and will never process your "starred" attribute.

                   

                  Thanks -- David

                  • 7. Re: How can I add a custom attribute to the create page dialog?
                    aslkit Level 1

                    I have follow the step state in the reference link but fail to create the page.

                     

                    Following are my step:

                     

                    1. Create the bundle using the code under \bundle\src\main\java\com\adobe\support\wcm\commands and I can see it is running under system/console/bundle

                    1a.png

                     

                    2. Edit those code for adding a field when creating page

                     

                    var createDialog = {

                            "jcr:primaryType": "cq:Dialog",

                            "id": CQ.Util.createId("cq-createdialog"),

                            "title":CQ.I18n.getMessage("Create Page"),

                            "formUrl": CQ.shared.HTTP.externalize("/bin/wcmcommand"),

                            "params": {

                                                     "cmd":"createPageWithCustomProperties",

                                "_charset_":"utf-8"

                            },

                            "height": 520,

                            "items": {

                                "jcr:primaryType": "cq:Panel",

                                "items": {

                                    "jcr:primaryType": "cq:WidgetCollection",

                                    "title": {

                                        "fieldLabel":CQ.I18n.getMessage("Title"),

                                        "allowBlank":false,

                                        "name":"title"

                                    },

                                    "label": {

                                        "fieldLabel":CQ.I18n.getMessage("Name"),

                                        "vtype":"itemname",

                                        "name":"label"

                                    },

                                    "starred": {

                                        "fieldLabel":CQ.I18n.getMessage("Starred"),

                                        "xtype":"checkbox",

                                        "name":"starred"

                                    },

                     

                    1a.png

                     

                    3. However, error msg throw when I create the page

                    1a.png

                     

                    Any step I have missed?

                    • 8. Re: How can I add a custom attribute to the create page dialog?
                      dcollie Adobe Employee

                      Sorry you are having issues, it was a quick sample that works for me on CQ5.5   It's hard for me to say what the error is from the info you have given.   Do you have any errors in your error.log?   Does a Charles HTTP trace of give any details in the Response to your Create page?    Have you set up the code in Eclipse (or similar) and stepped through it in debug mode?

                      • 9. Re: How can I add a custom attribute to the create page dialog?
                        aslkit Level 1

                        I am also working on CQ5.5

                         

                        The following is what system post when creating a page:

                         

                        cmd=createPageWithCustomProperties&_charset_=utf-8&%3Astatus=browser&parentPath=%2Fcontent%2Fkeyword_elaboration&title=a1&label=a&starred=on&template=%2Flibs%2Fcollab%2Fcommons%2Ftemplates%2Fform

                         

                        No related error log found in the error.log.

                        • 10. Re: How can I add a custom attribute to the create page dialog?
                          dcollie Adobe Employee

                          I downloaded the code, built the content package with bundle and deployed into a fresh CQ5.5 instance and it all works for me.   One thing could be the Session.impersonate, which uses "author" as it's value.   That would need to present in your instance (or alter the code to use the admin session to save the node changes as a test).   If it still doesn't work, I would suggest debugging the source code supplied and stepping through to find out where it is breaking on your instance.

                          • 11. Re: How can I add a custom attribute to the create page dialog?
                            aslkit Level 1

                            I wonder if the bundle has been triggered or not when creating the page. I have tried to out print some msg in the java code but no msg found in the error.log.

                             

                            Can the zip file provided by you directly installed in a clean cq5.5 enviornment? I think it cannot be installed through package manager. Are there any way to do that?

                             

                            When I access /bin/wcmcommand?cmd=createPageWithCustomProperties&_charset=_=utf-8, "Unknown action" is shown. Will this also happen in your enviornment?

                            • 12. Re: How can I add a custom attribute to the create page dialog?
                              dcollie Adobe Employee

                              That is exactly what I tested on a brand new CQ  5.5.  1) downloaded packaged and unzipped; 2) mvn clean install on bundle and content; 3) uploaded produced content package via Package manager.

                              • 13. Re: How can I add a custom attribute to the create page dialog?
                                aslkit Level 1

                                Thanks. It works fine for me.

                                 

                                However, how can I modify the code as it seems that only the jar installed in cq?