8 Replies Latest reply on Jan 17, 2013 3:11 AM by sarwarbhuiyan

    Using CQ to generate HTML




      Our current implementation invloves passing a serialised object via a GET request to a Sling servlet, it is deserialsed, the object is added as a request attribute and forwarded  to a relavent JSP page depending on a property in the object.

      This implementation will not work for large amounts of data due to the limitations of HTTP GET. HTTP POST requests do not work in Adobe CQ as it thinks that we are modifing the resource.


      We need another way to pass in our object to the Servlet and return HTML. How is this possible/feesable in Adobe CQ?





        • 1. Re: Using CQ to generate HTML
          justin_at_adobe Adobe Employee

          Making HTTP POSTs is fine in CQ. You just need to ensure that the request is being sent to the correct servlet (which it doesn't sound like it is).

          • 2. Re: Using CQ to generate HTML
            ryan125 Level 1

            With the POST, we are forwaring the request to a URL that contains our JSP template that will generate HTML. However CQ thinks that it needs to modify the URL of the servlet.

            • 3. Re: Using CQ to generate HTML
              Jörg Hoh Adobe Employee



              So you need to make sure, that your template is able to handle the POST request. The easiest way would be to add a "POST.jsp" to your page component.



              • 4. Re: Using CQ to generate HTML
                ryan125 Level 1

                When I do that CQ tries to modify the URL of the servlet - I get a ConstrainViolationException. What I need is to be able to return the HTML generated from the JSP page.

                • 5. Re: Using CQ to generate HTML
                  Davide G Adobe Employee

                  If you create a POST.jsp in your template/component and make it simple with only an Hello World and stop. Does it render correctly? Do you see the hello world?


                  Otherwise your POST.jsp is not being triggered on your post.



                  • 6. Re: Using CQ to generate HTML

                    There is a second part to this problem.  Even if you use a POST JSP or a POST Servlet, when you want to forward to another page, you can't just do a normal dispatcher forward.  You have to either do a response redirect and pass data in the session (might not be preferable) or you need to pass in some custom HttpServletRequest whose getMethod() returns "GET".  This is what the mechanism used by CQ5's FormHandlingServlet.

                    1 person found this helpful
                    • 7. Re: Using CQ to generate HTML
                      ryan125 Level 1

                      Thanks @sarwarbhuiyan for understanding the problem. In our situation it is not feasable to do a response redirect or use the session.

                      Our company did a POC with Adobe on this very problem, however the implementation is not appropriate.

                      I am looking for an answer of how our company can use Adobe CQ on this problem without having to do anything fancy with an HttpServletRequest object.

                      Any ideas?

                      • 8. Re: Using CQ to generate HTML
                        sarwarbhuiyan Level 1

                        Have you had a look at how the CQ5 form components are developed?  see [1]


                        Basic steps are:

                        1. Make a form component which has method="POST" and action="<%=currentPage.getPath()%>

                        2. Make an action component where the sling:resourceType property is set to foundation/components/form/action

                        3. In the form component, set an input field (type hidden) with name :formstart (notice the : before the name) and set the value to a content node (somewhere accessible).  Create that node, set sling:resourceType to foundation/components/form/start and actionType to the resourceType of the action you made in 2 (e.g. myapp/components/actions/myaction)

                        4. In the action component, put a post.POST.jsp in there.  This will be your POST handler.  In here, call any java logic or send your data form post data to an OSGi service to do whatever processing is required.  Then at the end of the forward.jsp you have a choice or where to redirect.  Or you can choose to display something here.  Your choice. 

                        Or the alternative in step 4 is instead of post.POST.jsp, put a forward.jsp and put in a FormHelper.setForwardPath(request, path) where path is a URL which is backed by another script (servlet or component jsp) that does the processing.  It will be a GET request though I believe.


                        Have a look at the /libs/foundation/components/forms folder and a few others which shows examples of these. 


                        Hope this helps.


                        1. http://dev.day.com/docs/en/cq/current/developing/developing-forms.html