title: JSF property transfer from backing bean A to backing bean B
body: <p>I'm getting deeper into JSF 2.0 at the moment and lacking a bit of understanding about the "transport" of managed bean properties from one view to the other. I searched a bit but haven't found a really good example, so if anyone could point me to a tutorial or explain the things a little bit I'd really grateful.</p>
  
  <p>So here is my scenario:</p>
  
  <p>I'm developing a small playground calendar application. The first view <code>select.xhtml</code> contains the calendar selector, where the user can pick a specific date:</p>
  
  <pre><code>&lt;html&gt;
    ...
    &lt;h:form&gt;
  
      &lt;!-- Calendar selector from primefaces --&gt;
      &lt;p:calendar value="#{calendarSelect.date}" mode="inline" navigator="true" /&gt;
  
      &lt;p:commandButton value="Show entries for date" action="day" /&gt;
      ...
  </code></pre>
  
  <p>My corresponding backing bean looks like this:</p>
  
  <pre><code>@ManagedBean(name="calendarSelect")
  @RequestScoped
  public class CalendarSelectComponent {
  
    private Date date = null;
  
    ... // Getters and setters
  </code></pre>
  
  <p>Now when I submit the form from <code>select.xhtml</code> I'm forwarded to <code>day.xhtml</code></p>
  
  <pre><code>&lt;html&gt;
    ...
    &lt;h:form&gt;
  
      The current day ist:
      &lt;h:outputText value="#{calendarEdit.date}"&gt;
        &lt;f:convertDateTime pattern="dd.MM.yyyy" /&gt;
      &lt;/h:outputText&gt;
  </code></pre>
  
  <p>The backing bean now looks like this:</p>
  
  <pre><code>@ManagedBean(name="calendarEdit")
  @ViewScoped
  public class CalendarEditComponent implements Serializable {
  
    private Date date = null;
    private CalendarEntryBean currentEntry = null;
    private List&lt;CalendarEntryBean&gt; allEntries = null;
  
    ....
  </code></pre>
  
  <p>I am now trying to solve the problem: How do I transfer the <code>date</code> parameter from the <em>selector</em> to the <em>editor</em>?</p>
  
  <p>I've tried a number of options, one was this:</p>
  
  <pre><code>&lt;p:commandButton value="Show entries for date" action="day" /&gt;
    &lt;f:setPropertyActionListener target="#{calendarEdit.date}" value="#{calendarSelect.date}" /&gt;
  &lt;/p:commandButton&gt;
  </code></pre>
  
  <p>A debugger shows, that indeed, the <code>date</code> property of the <code>calendarEdit</code> is populated with the value from <code>calendarSelect</code>, but since <code>day.xhtml</code> is a new view, a new <code>CalendarEditComponent</code> backing bean is being created and not the one I've populated with the date from the selector in the <code>select</code> view.</p>
  
  <p>I've read that one solution would be to create a <code>SessionScoped</code> backing bean that does retain all it's values. But this is not the way I think it's supposed to work, because I don't really need the information in the <em>session</em>, I simply want it to "travel" from A to B. Another downside with the session based approach is that I can only use one selector and one editor per session - which I think isn't acceptible if you think of multi window browsing and so on.</p>
  
  <p>I really don't think I'm the first one encountering such a scenario and I'm sure that JSF provides an elegant solution for this but I haven't been able to find that solution.</p>
  
  <p>So once again, if anyone knows how to approach this - I'm listening! ;-)</p>