title: How do you pass view parameters when navigating from an action in JSF2?
body: <p>From an action in my bean, I'm trying to redirect to another page expecting a view parameter. What is the recommended way to do this in JSF2?</p>
  
  <p>E.g., say my source page is:
  <a href="http://localhost/page1.xhtml" rel="nofollow noreferrer">http://localhost/page1.xhtml</a></p>
  
  <p>it has a commandButton that calls an action:</p>
  
  <pre><code>&lt;h:commandButton value="submit" action="#{myBean.submit}" /&gt;
  </code></pre>
  
  <p>where my bean looks like:</p>
  
  <pre><code>@ManagedBean
  @RequestScoped
  public class MyBean {
  
  private int id;
  
  public String submit() {
      //Does stuff
      id = setID();
      return "success";
  }
  </code></pre>
  
  <p>And now, I want the 'submit' action's return to navigate to
  <a href="http://localhost/page2.xhtml?id=2" rel="nofollow noreferrer">http://localhost/page2.xhtml?id=2</a></p>
  
  <p>I've tried to do this with a view-param in my navigation case, but with odd results. The faces-config snippet looks like the following:</p>
  
  <pre><code>&lt;navigation-rule&gt;
      &lt;from-view-id&gt;/page1.xhtml&lt;/from-view-id&gt;
      &lt;navigation-case&gt;
          &lt;from-outcome&gt;success&lt;/from-outcome&gt;
          &lt;to-view-id&gt;/page2.xhtml&lt;/to-view-id&gt;
          &lt;redirect&gt;
              &lt;view-param&gt;
                  &lt;name&gt;id&lt;/name&gt;
                  &lt;value&gt;#{myBean.id}&lt;/value&gt;
              &lt;/view-param&gt;
          &lt;/redirect&gt;
      &lt;/navigation-case&gt;
  &lt;/navigation-rule&gt;
  </code></pre>
  
  <p>The weird behaviour being, even though myBean is set to request scoped, it only calls <code>myBean.getId()</code> the first time I load my application, and reuses that same value for all subsequent calls, producing incorrect view parameters for page2.</p>
  
  <p>So I'm looking for either a better way to do this, or a reason/solution for why the view-param is not being requested from my bean each time.</p>