13 Replies Latest reply: Sep 30, 2012 1:36 PM by Antoine Herzog RSS

Portal URL Parameters pass to Portlet ?

Marc Stuart Newbie

Hello, I am trying to append parameters to the Portal URL, and the retrieve them in the portlet.

 

If I append a name value pair to the portal page

 

http://localhost:8080/portal/public/classic?some_param=some_value

 

How can I

In my portlet.xml I tried using public-render-parameter's ala :

 

<supported-public-render-parameter>some_param</supported-public-render-parameter>
   </portlet>
     <public-render-parameter>
             <identifier>some_param</identifier>
             <qname xmlns:x="http://sun.com/params">some_param</qname>
        </public-render-parameter>

 

 

and then in my portlet code

 

 

    public void doView(RenderRequest request, RenderResponse response) {
              try {
                     String someVar = request.getParameter("some_param");

 

But that doesn't seem to work, and even

 

String urlString = request.getRequestURL().toString();

 

doesn't offer me up a URL String.

 

Any ideas ??

  • 1. Re: Portal URL Parameters pass to Portlet ?
    Matt Wringe Expert

    That is not going to work, you should not be adding portlet url parameters to a portal url.

  • 2. Re: Portal URL Parameters pass to Portlet ?
    Joel Monkey Newbie

    You should be able to pass parameters and see then in the action phase of your portlet. See: http://community.jboss.org/wiki/PortletParameters

     

    It works in 2.7.2.

  • 3. Re: Portal URL Parameters pass to Portlet ?
    Art Munro Newbie

    Does this work in Gatein?  Mark have you tried this?

  • 4. Re: Portal URL Parameters pass to Portlet ?
    Zoltán Csorba Newbie

    Hi,

      I'm facing the same problem.

     

    I'd like to access portal request parameters or portal URL from the portlets, but I don't know how.

    I need to implement restful URL's for the portal.

     

    For example:

    Original URL: http://localhost:8080/myportal/item-123

    This should be redirected (with url rewrite filter) to: http://localhost:8080/myportal/showItem?id=123

    There is a showItem portal page, which contains a portlet that should show given item details.

     

    How could I access the request parameter 'id' from the portlet context?

    Maybe I'm wrong, and this not a good solution for handling 'nice' URLs in a portal?

     

    I'm using: GateIn-3.0.0-GA, PortletBridge-2.0.0.FINAL, Seam-2.2.0.GA

     

    Thank you in advance

  • 5. Re: Portal URL Parameters pass to Portlet ?
    Zoltán Csorba Newbie

    The solution I've found is the combination of org.tuckey UrlRewriteFilter and a PhaseListener.

    The PhaseListener implementation is based on this blogpost: http://blogs.steeplesoft.com/2006/04/jsf-phaselisteners-and-get-requests/

    The main difference is, that I've extended the configuration with portlet path info. This means, I can configure parameter handling rules per portlet. This helps avoiding repeated execution of parameter injections (because the phase listener is executed once for each portlet instances on a portal page).

     

    That's all.

  • 6. Re: Portal URL Parameters pass to Portlet ?
    Jorge Ferreyra Newbie

    Hi ZoltÃin.

    Could you show me some of your source code of PhaseListener? Especially, how you did get the url of portal, because, when I try get it, an exception is thrown:

     

    context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest)context.getExternalContext().getRequest();
    String uri = request.getRequestURI();
    

     

    The exception is produced because the method getRequest returns an RenderRequest object , but it needs a HttpServletRequest object. The problem is I don't have any idea about how to get the HttpServletRequest.

     

    if you have any example of this I would appreciate your help.

     

    I'm using Gatein 3.0.0-GA and JBossPortetBridge 2.0.0.FINAL

  • 7. Re: Portal URL Parameters pass to Portlet ?
    Zoltán Csorba Newbie

    Hi Jorge,

      I use org.gatein.pc.portlet.impl.jsr168.api.RenderRequestImpl and javax.servlet.http.HttpServletRequestWrapper.

     

     

        private void debugRequest(RenderRequestImpl renderRequest, HttpServletRequestWrapper hsrw) {
            RequestParamHandlerPhaseListener.logger.debug("URI: " + hsrw.getRequestURI());
            RequestParamHandlerPhaseListener.logger.debug("Portlet request path info: " + renderRequest.getAttribute("org.jboss.seam.web.requestPathInfo"));
            if (RequestParamHandlerPhaseListener.logger.isTraceEnabled()) {
                RequestParamHandlerPhaseListener.logger.trace("  Parameters...");
                @SuppressWarnings("unchecked")
                Map<String, String[]> params = hsrw.getParameterMap();
                for (String key : params.keySet()) {
                    RequestParamHandlerPhaseListener.logger.trace("    param: " + key + " = " + Arrays.toString(params.get(key)));
                }
                RequestParamHandlerPhaseListener.logger.trace("  End of parameters");
            }
        }
    
        @Override
        public PhaseId getPhaseId() {
           // TODO read configuration...
           return PhaseId.RESTORE_VIEW;
        }
    
        private void processRequest() {
            FacesContext context = FacesContext.getCurrentInstance();
            ExpressionFactory ef = context.getApplication().getExpressionFactory();
            Object reqObj = context.getExternalContext().getRequest();
            if (RequestParamHandlerPhaseListener.logger.isTraceEnabled()) {
                RequestParamHandlerPhaseListener.logger.trace("Request class: #0", reqObj.getClass().getName());
            }
            if (reqObj instanceof RenderRequestImpl) {
                RequestParamHandlerPhaseListener.logger.trace("Handling RenderRequest...");
                RenderRequestImpl renderRequest = (RenderRequestImpl) reqObj;
                HttpServletRequestWrapper hsrw = renderRequest.getRealRequest();
                if (RequestParamHandlerPhaseListener.logger.isDebugEnabled()) {
                    this.debugRequest(renderRequest, hsrw);
                }
                String uri = hsrw.getRequestURI();
                String contextPath = hsrw.getContextPath();
                // comment: there is no static field for "org.jboss.seam.web.requestPathInfo" 
                String reqPathInfo = (String) renderRequest.getAttribute("org.jboss.seam.web.requestPathInfo");
                // reqPathInfo is the viewId of currently processed portlet
    
                // TODO process request URI and parameters...
            }
        }
    

     

     

    I hope it helps you.

     

    Regards,

      Zoltan

  • 8. Re: Portal URL Parameters pass to Portlet ?
    Jorge Ferreyra Newbie

    It works!. Thank you very much, Zoltan.

  • 9. Re: Portal URL Parameters pass to Portlet ?
    Minh Hoang TO Novice

    From coming release 3.2, some navigational properties of portal would be accessible as portlet public render parameter. Here is link to relevant JIRA

     

    https://jira.jboss.org/browse/GTNPORTAL-1398

  • 10. Re: Portal URL Parameters pass to Portlet ?
    Antoine Herzog Master

    Also, with the release 3.2, a Url factory and decoder has been added.

    This will allow to manage more easily the url building and url use.

     

    See : http://community.jboss.org/en/gatein?view=blog

    chapter : "Improved URLs"

     

    And the Navigation Controller :

    http://docs.jboss.org/gatein/portal/3.2.0.Final/reference-guide/en-US/html/chap-Reference_Guide-Development.html#sect-Reference_Guide-Navigation_Controller

     

    The Navigation Controller should be helpfull for what you need.

     

    Antoine

    JBoss Portal and GateIn, JSF, Richfaces, J2EE.

    http://www.presta-expert.com/

  • 11. Re: Portal URL Parameters pass to Portlet ?
    Sreenivas Reddy Kandula Newbie

    Hi,

     

    How can we get PortletUrl in jsr268 into portlet controller or into jsp ???

  • 12. Re: Portal URL Parameters pass to Portlet ?
    Vu Viet Phuong Novice

    For jsp, you can use Portlet Tag Library, the details is in JSR 268 spec. For example, you can have a tag like this to generate action url:

    <portlet:actionURL windowState=”maximized” portletMode=”edit” name=”editStocks”>

    </portlet:actionURL>

     

    In your portlet class, you can use RenderResponse#createRenderURL , this is also mentioned in JSR 268

  • 13. Re: Portal URL Parameters pass to Portlet ?
    Antoine Herzog Master

    Hi,

     

    you have also plenty of sample in the code of GateIn itself.

    look into the Groovy files (".gtmpl"), there are many samples of how to build some url of other pages, with parameters, etc...

    thoses files are in the code source, but also in the server, directly readable when the ear and war are not zipped.

    make a search with the PortletUrl key word, etc...

     

    you can adapt things from the Groovy sample, to the JSP (quite similar way of doing these kind of things...)

     

    Antoine

    JBoss Portal, EPP, and GateIn, J2EE, JSF, Richfaces, JBoss AS7.