2 Replies Latest reply on Jul 2, 2010 12:41 AM by jferreyram

    IPC / Redirect portal page from a portlet

    jferreyram

      Hello

      Because I can't pass a public render parameter (PRP) and redirect to another portal page from my portlet, I'm using javascript to do it. But, at first time this PRP is null, recent works the second time.

       

      The portlet 'A' (located in page '1') set the PRP and call a javascript function which redirect to the page '2' , and portlet 'B' (located in page '2') will receive the public parameter.

       

      Porlet 'A'  (located in http://localhost:8080/portal/public/Intralot/home) :

       

      home.xhtml:

      <script type="text/javascript">
      function redirect(){
          SideBar_RedirectUrl = 'http://#{facesContext.externalContext.request.serverName}:#{facesContext.externalContext.request.serverPort}/portal/public/Intralot/home/detail';
          setTimeout( "window.location.href = SideBar_RedirectUrl", 1000 );
      }
      </script>
      
      <h:commandLink action="#{myBean.detail}" value="A title" onclick="redirect();">
              <f:param name="param" value="1"/>
      </h:commandLink>
      

       

      MyBean.java:

       

      public String detail(){
              try {
                  FacesContext context = FacesContext.getCurrentInstance();
                  PortletRequest request = (PortletRequest) context.getExternalContext().getRequest();
                  String parameter = request.getParameter("param");
                  if(parameter!=null){
                      this.par = parameter;    
                      Object response = context.getExternalContext().getResponse();
                      if (response instanceof StateAwareResponse) {
                          StateAwareResponse stateResponse = (StateAwareResponse) response;
                          stateResponse.setRenderParameter("prp",parameter);
                      }
                  }else{
                      System.out.println("Null parameter");
                  }            
              } catch (Exception e) {
              }
              return null;
      }
      

       

      Portlet 'B':

      MyBean.java:

       

      try {
                  FacesContext context = FacesContext.getCurrentInstance();
                  PortletRequest request = (PortletRequest) context.getExternalContext().getRequest();
                  String parameter = request.getParameter("prp");
                  if (parameter != null && parameter.trim().length()!=0)
                       //using the parameter 'prp'
      }catch (Exception e) {
       }
      

       

       

      I repeat, this work, except the first time, and don't know why.

       

      Anyone can help me and tell me the reason, please????

        • 1. Re: IPC / Redirect portal page from a portlet
          jjamrich

          Only guessing..... are you sure that parameter you received "next" time isn't "lost" parameter from previous call?

           

          I mean, firstly you set PRP (value "prpVal-1") from portlet A, and redirect do portlet B, and try to retrieve PRP set from portlet A, but you get null.

          Next time, you set PRP again.... but now try to set value "prpVal-2", and redirect to portlet B.... I think you get value "prpVal-1" instead of "prpVal-2".

           

          Only suggestion, I'm not sure if this helps, .... try use JSF redirect (FacesContext.getCurrentInstance().getExternalContext().redirect("http://www.google.com");) instead of redirect invoked by JS....

          • 2. Re: IPC / Redirect portal page from a portlet
            jferreyram

            Hi Jan, thank you for your answer.

            In fact, it occurs the situation that you describe, some times, but occurs. Now, this problem is critical if I test it in Google Chrome. In that browser the portlet 'B' never (or almost never) receive the parameter.

            I tried to use redirect method, but an exception is thrown, and log 'say' me I can't use redirect method after calling setRenderParameter method.

            For these reasons, I use javascript to redirect, but that is'nt stable solution.