title: Can the Flash data be persisted after redirection?
body: <p>Using JSF 2.1.29</p>
  
  <p>In <strong>list.xhtml</strong></p>
  
  <pre><code>&lt;p:commandLink id="ownerViewLinkId" value="#{petOwner.firstName} #{petOwner.lastName} " 
  action="#{ownerAndPetListBean.viewPetOwnerFrmList(petOwner.id,petOwner.userId,0)}"
          onclick="PF('progrees_db').show()"
          oncomplete="PF('progrees_db').hide()"
          style="color:#0080FF;"&gt;
  &lt;/p:commandLink&gt;
  </code></pre>
  
  <p>In <strong>listBean</strong> (viewscoped),</p>
  
  <pre><code>public void viewPetOwnerFrmList(String ownerIdStr, String userIdStr,
              String petIdStr) {
      try {
          FacesContext.getCurrentInstance().getExternalContext().getFlash().put("ownerId",ownerIdStr);
              FacesContext.getCurrentInstance().getExternalContext().getFlash().put("userId",userIdStr);
              FacesContext.getCurrentInstance().getExternalContext().getFlash().put("petId",petIdStr);
  
              FacesContext.getCurrentInstance().getExternalContext()
                      .redirect("/ownerandpets/view");
  
      } catch (Exception e) {
              log.warn("FL Warning", e);
      }
  }
  </code></pre>
  
  <p><strong>pretty-config.xml</strong></p>
  
  <pre><code>  &lt;url-mapping id="ownerandpetsview"&gt; 
        &lt;pattern value="/ownerandpets/view" /&gt;          
        &lt;view-id value="/WEB-INF/views/ownerAndPet/OwnerAndPetsView.xhtml" /&gt;
        &lt;action onPostback="false"&gt;#{ownerAndPetViewBean.fillPage}&lt;/action&gt; 
    &lt;/url-mapping&gt;
  </code></pre>
  
  <p>In <strong>viewbean</strong> (viewscoped),</p>
  
  <pre><code>String petIdStr;
  String userIdStr;
  String ownerIdStr;
  String firstName;
  //include getters and setters
  public void fillPage() {
  
      petIdStr = (String) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("petId");
      userIdStr = (String) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("userId");
      ownerIdStr = (String) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("ownerId");
  
      System.out.println(ownerIdStr+" "+userIdStr+" "+petIdStr);
      firstName = getFromDBByOwnerId(ownerIdStr); 
  }
  </code></pre>
  
  <p>In <strong>view</strong> page,</p>
  
  <pre><code>&lt;h:outputText value="#{ownerAndPetViewBean.firstName}"/&gt;
  </code></pre>
  
  <p>firstName is displayed after redirect.
  On refreshing the view page (by pressing f5), the string firstName becomes null and id strings printed in viewBean's fillPage is null.
  What i need is on refresh, i need to refetch firstName for which the ids must not be null.
  Had gone through this <a href="https://stackoverflow.com/tags/flash-scope/info">link</a>
  Anyway to persist the flash data in request?</p>
  
  <p>Tried the below but was not successful :  </p>
  
  <p><strong>1.</strong></p>
  
  <pre class="lang-java prettyprint-override"><code>FacesContext.getCurrentInstance().getExternalContext()
                      .redirect("/ownerandpets/view?faces-redirect=true");
  </code></pre>
  
  <p><strong>2.</strong>
  </p>
  
  <pre><code>FacesContext.getCurrentInstance()
      .getExternalContext().getFlash().keep("ownerId");
  FacesContext.getCurrentInstance()
      .getExternalContext().getFlash().keep("userId");
  FacesContext.getCurrentInstance()
      .getExternalContext().getFlash().keep("petId");
  </code></pre>
  
  <p><strong>3.</strong>
  </p>
  
  <pre><code>FacesContext.getCurrentInstance().getExternalContext()
      .getFlash().setKeepMessages(true);
  FacesContext.getCurrentInstance().getExternalContext()
      .getFlash().setRedirect(true);
  </code></pre>
  
  <p>On Refresh debugging, the ids are there in the flash scope map on watching <code>FacesContext.getCurrentInstance().getExternalContext().getFlash()</code> , but the same is not displayed in watching <code>FacesContext.getCurrentInstance().getExternalContext().getFlash().get("petId");</code> (see fig 2).</p>
  
  <p><a href="https://i.stack.imgur.com/f0zEl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f0zEl.png" alt="Values in Flash Map on Refresh - Fig 1"></a>
  <a href="https://i.stack.imgur.com/9miT2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9miT2.png" alt="Fig 2"></a></p>
  
  <p><strong>Update 1 (Answer):</strong></p>
  
  <p>As suggested by Xtreme Biker, added preRenderView to the view page.</p>
  
  <p><code>&lt;f:event type="preRenderView" listener="#{ownerAndPetViewBean.fillPage}"/&gt;</code> .</p>
  
  <p>From the pretty-config.xml, remove or comment</p>
  
  <p><code>&lt;action onPostback="false"&gt;#{ownerAndPetViewBean.fillPage}&lt;/action&gt;</code> </p>
  
  <p>Put a not postback checking in fillPage method and added flash.keep in managed bean. </p>
  
  <pre><code>FacesContext.getCurrentInstance().getExternalContext().getFlash().keep("ownerId");
  </code></pre>
  
  <p>The above method will not work with pretty-faces action tag (if used instead of preRenderview) and we will get page with no values.</p>