title: JSF2.0 how do you pass a viewParam to a request scoped backing bean while using a commandButton?
body: <p>I have the following page:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;ui:composition
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:o="http://omnifaces.org/ui"
      xmlns:thehub="http://java.sun.com/jsf/composite/components/thehub"
      template="/templates/masterTemplate.xhtml"&gt;
      &lt;f:metadata&gt;
          &lt;f:viewParam
              id="returnToViewParam"
              name="returnTo"
              value="#{loginMB.returnTo}"
              required="true" /&gt;
          &lt;f:viewParam
              id="oauth_verifierViewParam"
              name="oauth_verifier"
              value="#{loginMB.oauth_verifier}" /&gt;
          &lt;f:viewParam
              id="oauth_tokenViewParam"
              name="oauth_token"
              value="#{loginMB.oauth_token}" /&gt;
          &lt;f:event
              type="preRenderView"
              listener="#{loginMB.preRenderView()}" /&gt;
      &lt;/f:metadata&gt;
  
      &lt;ui:define name="body"&gt;
          &lt;o:form
              id="loginForm"
              includeViewParams="true"&gt;
              &lt;div class="form-vertical well"&gt;
                  &lt;h4&gt;New Users&lt;/h4&gt;
                  &lt;h5&gt;
                      &lt;h:link outcome="signup"&gt;Click here to create an account&lt;/h:link&gt;
                  &lt;/h5&gt;
                  &lt;hr /&gt;
                  &lt;h4&gt;Existing Users&lt;/h4&gt;
                  &lt;h:commandButton
                      id="googleLoginCommandLink"
                      styleClass="btn"
                      action="#{loginMB.redirect()}"
                      value="Google"&gt;
                      &lt;f:param
                          name="returnTo"
                          value="#{param.returnTo}" /&gt;
                  &lt;/h:commandButton&gt;
                  &lt;div class="clearfix"&gt;&lt;/div&gt;
              &lt;/div&gt;
          &lt;/o:form&gt;
      &lt;/ui:define&gt;
  &lt;/ui:composition&gt;
  </code></pre>
  
  <p>And the following bean:</p>
  
  <pre><code>@ManagedBean
  @RequestScoped
  public class LoginMB implements Serializable {
  private static final long serialVersionUID = 1L;
  
  private String returnTo;
  
  public void redirect() {
      log.debug("redirect() returnTo:{}", returnTo);
  
  ......getter/setters
  }
  </code></pre>
  
  <p>No matter what I do, I can't seem to get returnTo bound once the commandButton is clicked. Since this is a login page, I'd really  <em>not</em> like to have LoginMB be a @ViewScoped bean.</p>
  
  <p>Advice? Is there a better way to handle this scenario?</p>
  
  <p>EDIT:</p>
  
  <ul>
  <li>I'm running this on TomEE+ Server v1.5.1 which is served up by MyFaces 2.1.10</li>
  <li>Added full page</li>
  <li>Clarified the problem: Inside the <code>redirect()</code> function, returnTo is null</li>
  </ul>