3 Replies Latest reply on May 26, 2011 7:17 PM by lessonz

    Page Redirect

    lessonz

      Hopefully I'm missing something obvious. How can I do a simple URL redirect to (and here's the kicker) a URL specified in the backing bean? Thanks.

        • 1. Re: Page Redirect
          ppitonak

          Hi,

           

          faces-redirect=true is probably what you're looking for. Just append it to the outcome of your method.

           

          public String foo () {

              //...

             return "/bar/welcome?faces-redirect=true";

          }

           

          Regards,

          Palo

          • 2. Re: Page Redirect
            lessonz

            Pavol, I appreciate the response, but I'm not sure I understand. I'm looking for the front end code to redirect to a URL that is present in the backing bean. When the bean enters scope, it's reading this in from a configuration file. So, I want the front end to be able to use that value.

            • 3. Re: Page Redirect
              lessonz

              I ended up using something like this:

               

              <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

               

              <html xmlns="http://www.w3.org/1999/xhtml"

                    xmlns:h="http://java.sun.com/jsf/html">

                  <script type="text/javascript">

                      function redirect(url){

                          window.location = url;

                      }

                     

                  </script>

                  <h:head >

                      <title>Facelet Title</title>

                  </h:head>

                  <h:body onload="redirect('#{redirectBean.url}')" >

                      <h:outputText value="#{redirectBean.url}"/>

                      <p>Hello from Facelets</p>

                  </h:body>

              </html>