6 Replies Latest reply on Jan 23, 2013 6:23 AM by kasq

    How to make a text as a CQ component?

    apark2900

      Hi,

       

      I am a newbee in CQ development, so please bear with me if I ask too obvious question.

       

      I created a template which diplays a title and summary of page in WCM be below.

      I originally put these two values of properties into each page node using CRXDE Lite.

       

      ------template.jsp---------------------------------------------------------------

      <% String currentTitle = currentPage.getTitle();

      String summary = currentPage.getProperties().get("summary",""); %>

       

      <h1><%=currentTitle%></h1>

      <p><%=summary%></p>

       

      -----------------------------------------------------------------------------------

       

      It successfully display the title for each pages in WCM structure. However, when I click into a page from WCM.

      I cannot edit the content of summary as I can edit using a CQ component of text. If I want to edit I have to go back to CRXDElite and

      browse the page's jcr:content and find the summary property to edit it.

       

      I tried this.

       

      -------template.jsp(what I  tried)-----------------------------------------------

      <% String currentTitle = currentPage.getTitle();

      String summary = currentPage.getProperties().get("summary",""); %>

       

      <h1><%=currentTitle%></h1>

      <cq:text property="text"/>

      <p><%=summary%></p>

      -----------------------------------------------------------------------------------

      But it displays CQ component and my text seperately.

       

       

       

      Is there anyway I can do this like this?

       

      <cq:text property="text" value="<%=summary%>"/>

        • 1. Re: How to make a text as a CQ component?
          kasq Level 3

          Hi,

           

          Try to read documentation from the following links to understand how components work and for sure how to start implementation for them:

           

          -> http://dev.day.com/docs/en/cq/current/developing/components.html

          -> http://dev.day.com/docs/en/cq/current/howto/components_develop.html

          -> http://dev.day.com/docs/en/cq/current/getting_started/first_steps_for_developers.html

           

          My suggestion is first of all to create a custom component "summary" under  "/apps/yourapp/components/summary" with some dialog to set summary description and of course some summary.jsp to render it on the page. So summary.jsp will contains something like

           

          <% String summary= properties.get("summary", String.class); %>

          <p><%=summary%></p>

           

          Finally you need to inlclude in your template.jsp component:

           

          <cq:include path="summary" resourceType="yourapp/components/summary"/>

           

          Then if you open a page in the EDIT mode you should have possiblity open a dialog for this component and specify a summary.

          After click ok on the DIALOG value for summary should be present on the page. This is of course quick overview, so better please check link with documentation.

           

          I hope that somehow helps you.

           

          Regards,

          kasq

          • 2. Re: How to make a text as a CQ component?
            apark2900 Level 1

            Thanks Kasq. I got the concept. Now I need to do some due diligences to read documents that you recommended.

            • 3. Re: How to make a text as a CQ component?
              apark2900 Level 1

              Hi Kasq,

               

              I tried as you mentioned above. I am getting close. But I have one big issue. Here is what I found.

               

              I copied a text component from libs/foundation/components/text and save under apps/myproject/components/text.

              Tweek a little bit for path and place below code to the text.jsp:

               

               

              <%@include file="/libs/foundation/global.jsp"%>

                <% String summary=properties.get("summary",String.class); %>

              <%=summary%>

               

              Originally the text.jsp was as:

               

              <%@include file="/libs/foundation/global.jsp"%>

              <cq:text property="text"/>

               

              -------------------------------

               

               

              Now I included this code, <cq:include path="text" resourceType="myproject/components/text"/> in my template file.

              I successfully retrieve the summary on my template page. And I also can click and open an dialog in this summary area.

               

              However, the summary value is not inside of this dialog. In addition to that, whatever I edit in this dialog doesn't go to my

              summary value.

               

              When I put <cq:text property="text"/> under my code in text.jsp, the added contents from the dialog appeared, but under the value of summary.

               

              Now, my question is how can I associate my summary value with component's value?

              • 4. Re: How to make a text as a CQ component?
                Sham HC Level 7

                Hi Apark,

                 

                Following all the steps of kasq should work.  My suspect in your case you have not modified the value at [1]  from "./text" to "./summary"

                 

                [1]    /apps/myproject/components/text/dialog/items/tab1/items/text

                 

                Thanks,

                Sham

                • 5. Re: How to make a text as a CQ component?
                  apark2900 Level 1

                  Hi Sham,

                   

                  What does it mean to change from "./text" to "./summary"?

                  How does CQ recognize "summary" and put it in the dialog since it's a variable in text.jsp page?

                   

                  I actaully changed it but it's not working. To clarify, my text.jsp contains below code, nothing else.

                   

                  <%@include file="/libs/foundation/global.jsp"%>

                    <% String summary=properties.get("summary",String.class); %>

                  <%=summary%>

                  • 6. Re: How to make a text as a CQ component?
                    kasq Level 3

                    Hi Apark,

                     

                    If you open CRXDE Lite and navigate to "apps/myproject/components/text/dialog/items/tab1/items/text" there is property "name" which after copy from libs/foundation/components/text has probably value "./text". You need to change this property to "./summary" like Sham wrote in order to get it in the component jsp using this code:

                     

                    <% String summary=properties.get("summary",String.class); %>

                     

                    So if you edit component on the page, specify some value for summary field, it will be stored in the property "summary". In other case when you copied text component from libs and you didn't change property name it stores value for summary filed in the text property, so code does not work.

                     

                    Regards,

                    kasq