1 2 Previous Next 17 Replies Latest reply on Apr 27, 2011 4:54 AM by trong.tran

    Get "GET" parameter for a portlet?

    skau

      Hi gatein forum members,

       

      I tried to create a portlet which displayed my get parameter from the url.

      The Code of the portlet looks like:

       

      public voidprocessAction(ActionRequest request, ActionResponse response) throwsPortletException, PortletSecurityException, IOException

         {

            Enumeration e =request.getParameterNames();

            String name;

            while (e.hasMoreElements()) {

               name = (String) e.nextElement();

              response.setRenderParameter(name,request.getParameter(name));

            }

         }

       

         protected void doView(RenderRequest req,RenderResponse resp) throws IOException

         {

            try

            {

               resp.setContentType("text/html");

               StringBuffer html = newStringBuffer();

       

               html.append("<br/>");

               html.append("<b>HelloPortal World!</b>");

               html.append("<br/>");

              html.append("<BR/><BR/>RenderRequest Parameters");

               Enumeration e =req.getParameterNames();

               String name;

               while (e.hasMoreElements()) {

                  name = (String) e.nextElement();

                 html.append("<BR/>  " + name +"="

                        + req.getParameter(name));

               }

       

              resp.getWriter().write(html.toString());

            }

            catch(Exception e)

            {

               e.printStackTrace();

            }

         }

       

      I made a page in my portal und add this portlet.

      After it I tried to browsed this page with

      http://localhost:8080/myportal/private/bth/Portlets?param1=eins&param2=zwei

      but my portlet don’t show any parameter.

      Has anyone an idea why I the request object don’t have any got parameter ?

       

      Cheers

      Steffen

        • 1. Get "GET" parameter for a portlet?
          rraposa

          It's not trivial to retrieve a GET parameter in a portlet. The logic is because the portlet is only a portion of a much larger portal page. At any rate, there is a way to retieve them using a PhaseListener. Have you seen this post:

           

          http://community.jboss.org/message/558924

          • 2. Get "GET" parameter for a portlet?
            trong.tran

            You can also retrieve the value of the paramter in URL's query string from a portlet if and only it is a public render paramter and supported in the Portlet.

             

            You could refer more detail about Public Render Paramters in the Portlet Spec 2.0

            • 3. Get "GET" parameter for a portlet?
              skau

              Hi Forum Member,

               

              Thanks for your reply.

              I thought the second succession sounded good and I tried to use a public render parameter.

              I wrote in my portlet.xml

              <portlet>

              ….

                  <supported-public-render-parameter>custID</supported-public-render-parameter>

              </portlet>

               

              <public-render-parameter>

                  <description>Apublic render parameter</description>

                  <identifier>custID</identifier>

                  <name>custID</name>

              </public-render-parameter>

               

              My URL looks like:

              http://localhost:8080/…../portlet?custID=123456

               

              Last but not least the java class:

              Protected void doView(RenderRequest renderRequest, RenderResponse renderResponse) throwsIOException {

              String param = (String) renderRequest.getAttribute(“custID”);

              }

               

              But the param is always null.

              Anybody knows my failure?

              I still useGateIN 3.1.0 GA

               

              Cheers

              Steffen

               

              P.S.

              I also tried to override the processAction Methode but these methode was never called.

              • 4. Get "GET" parameter for a portlet?
                vstorm83

                You can use render parameter or public render parameter, they will be used to render the portlet url --> user have to click on that url --> in render  (or doView... ) method, you can use the request.getParameter (not getAttribute) method to get these parameters

                • 5. Re: Get "GET" parameter for a portlet?
                  skau

                  Hi Vu Viet Phuong,

                   

                  thanks for your reply.

                  I changed the method call to request.getParameter("custID"); but the String is still null.

                   

                  Cheers,

                  Steffen

                  • 6. Get "GET" parameter for a portlet?
                    rraposa

                    I think what Vu Viet is saying is that INSTEAD OF using a URL parameter, you can use a public render parameter. But you can NOT get a URL parameter by simply calling the method request.getParameter("") inside of a portlet - it's not going to work. There is no single method call in a GateIn portlet to retrieve a URL parameter.

                     

                    Trong - are you sure your response is correct? I have not seen anything in the portlet spec about URL parameters needing to be public render parameters.

                     

                    Steffen - please read this post closely: http://community.jboss.org/message/550397

                    • 7. Re: Get "GET" parameter for a portlet?
                      skau

                      Hi Rich,

                      Thanks for your help.

                      I read this post but I thought with GateIn 3.2 I could used a way without added a PhaseListener.

                      So I trie dthe way with the public render parameter.

                      I thought it meant that I built an URL with an UrlRewriteFilter and after it I read this parameter from request object in my doView method.

                      Rich do you mean the way I tried is not possible and the only soulution is to take the example with the PhaseListener?

                       

                      Cheers;

                      Steffen

                      • 8. Re: Get "GET" parameter for a portlet?
                        rraposa

                        Steffen,

                         

                        I have not done this myself before, so I'm not sure how to do it. Using a PhaseListener is the only way I have heard it done in a portlet. However, I have written code to retrieve a URL parameter in a JSF backing bean over the PortletBridge, but I'm not sure that is your situation.

                         

                        Sorry I can't provide any example! I would be very interested in seeing the code if anyone out there has done this before.

                         

                        I think in the future GateIn needs to provide a simple mechanism for retrieving URL parameters. I realize it is not part of the spec, but it can be done in other portals like Liferay and Websphere.

                         

                        -Rich

                        • 9. Re: Get "GET" parameter for a portlet?
                          vstorm83

                          Actually, I don't modify the portlet url "by hand" , I have written a simple test :

                           

                          PortletURL renderURL = response.createRenderURL();

                          renderURL.setParameter("test", "testValue");

                          renderURL.toString();  --> put this to <a> html

                           

                          another way to set the parameter to url is that you can use the ActionResponse.setRenderParameter() method

                           

                          After click that URL --->  In the doView method, I call RenderRequest.getParameter() method --> and it works

                          @Steffen Kau : If you want I will send you that code, I hope this is what you need

                          • 10. Get "GET" parameter for a portlet?
                            skau

                            Hi Vu Viet Phuong,

                             

                            Thanks for your reply and your offer.

                            I am very interestin an example.

                            I think I should explain my current situation.

                            I need a page in a portal. This page only contains one portlet (the portlet I try to write). The URL of this page is

                            http://localhost:8080/portal/private/classic/Portlet.

                            My goal is that a user can write an URL (or bookmark this link or tell it a friend) like

                            http://localhost:8080/portal/private/classic/Portlet/BR1509 and a filter for URLRewriting change it to

                            http://localhost:8080/portal/private/classic/Portlet?custID=BR1509

                            I will resolve this problem with urlrewritefilter-3.2.0.

                            The next step should be that my portlet take this custID (GET-parameter) and looking for the product in my database.

                            After it the content for this product is shown in the portlet.

                             

                            Cheers,

                            Steffen

                             

                            P.S.

                            Is there any difference between to use the RenderResponse.getWrite methodfor writing html or use a separate jsp file for the contend view?

                            • 11. Get "GET" parameter for a portlet?
                              hoang_to

                              Let's put a break point in your method processAction to see if when you browse the page, the method is executed or not !

                              • 12. Get "GET" parameter for a portlet?
                                skau

                                Hi Minh Hoang To,

                                 

                                Thanks for your reply,

                                 

                                I was wrong with this question. When i called the portlet i had only a Render-Request because I browsed the portlet page directly from the bookmark.

                                 

                                So i have to change my question in

                                how do I get a get-parameter in an render-request without any action-request?

                                 

                                Cheers Steffen

                                • 13. Get "GET" parameter for a portlet?
                                  trong.tran

                                  Rich Raposa wrote:


                                  Trong - are you sure your response is correct? I have not seen anything in the portlet spec about URL parameters needing to be public render parameters.

                                  Actually what i meant is just : In GateIn, the public render parameters are visible obviously in URL. Let's say we have a following render URL :

                                   

                                  http://localhost:8080/portal/private/classic/portlet?portal:componentId=be954faf-e3de-4dfb-a370-55501bee19bf&navigationalstate=JBPNS_rO0ABXcxAAZwYXJhbTEAAAABAAZ2YWx1ZTEABnBhcmFtMgAAAAEABnZhbHVlMgAHX19FT0ZfXw**&zip-id=newValues

                                   

                                  You will see that only public render paramters are visible from URL ( zip-id=newValues in the case ). And it can be retrieved from the portlet which supported the public render paramter.

                                   

                                  Anyway, using of public render paramters seems not to fit in with Steffen Kau's need.

                                  • 14. Re: Get "GET" parameter for a portlet?
                                    skau

                                    Hi forum members,

                                    I got the solution from the exo forum.

                                    For GateIn you can use the Util.getPortalRequestContext().getRequestParameter(“custID”) method

                                    from the org.exoplatform.portal.webui.util.Util package.

                                     

                                    Cheers and have a nice weekend,

                                    Steffen.

                                    1 2 Previous Next