4 Replies Latest reply on Mar 22, 2013 3:54 AM by creative83

    How to pass argument to Page

    creative83 Level 1

      I wanted to pass argument to page using URL. I tryed below option:

       

      http://localhost:4502/cf#/content/mysite/en/add-product-page.html?pid=123

       

      I am able to pass argument in URL and also able to access. But the problem is for this kind of pages it refreshes page after loading. If I do not pass the argument it loads normaly, where as with argument it flickers visibly. What can I do to avoid this?

       

      Purpose: I have product page and I wanted to display product information on page based on ID passed to the page.

        • 1. Re: How to pass argument to Page
          Sham HC Level 7

          Hi Ujjval83,

           

          Use selectors look at http://blogs.adobe.com/contentmanagement/tag/sling-selector/

           

          Thanks,

          Sham

          • 2. Re: How to pass argument to Page
            creative83 Level 1

            Thanks for the reply. I use below code, similar to that only. But yours is more specific to CQ5. I will try to impliment.

             

            My Code:

            PathInfo pathInfo = new PathInfo(request.getRequestURI().toString());

            String pid = pathInfo.getSelectorString();

             

            Have few doubts about the link you gave:

             

            1) how they are retriving "selectors". Same way I am retriving?

            2)Also they are telling to pass the argument "page" but the probel is whenever I pass argument to page it refreshes twice.

            • 3. Re: How to pass argument to Page
              Andras Fejer Level 1

              Is it important for you to use parameters which are attached to the URI or could you also use session attributes?

               

              You can set session attributes with the following code:

               

              HttpSession session = this.getSlingRequest().getSession();

              session.setAttribute(name, value);

               

              and you can retrieve the attribute with:

               

              session.getAttribute(name);

              • 4. Re: How to pass argument to Page
                creative83 Level 1

                Session attribute I can use when I wanted jsut few information to be stored related to entire page. But here my requirement is, I have lsit of products, and all those contains a link, this link I am generating at runtime, which points to perticular page.

                 

                <a href=/content/abc/page.html?pid=111">Prod 111</a>

                <a href=/content/abc/page.html?pid=112">Prod 112</a>

                <a href=/content/abc/page.html?pid=113">Prod 112</a>

                 

                Now I generate this page dynamically, I am not sure on which product user selects, based on the product link user selected, argument needs to be passed.

                 

                That is why I can not use session and need to pass it as argument. But now I am not using argument as mentioned above, I am using selecor in argument.