title: JSF passing view parameters by reference - when object must be instantiated
body: <p>Let's say I've got a register page &amp; a register confirm page. I enter user
  details into the register page, navigate to the register confirm page where
  I can return back to the register page if there are any mistakes.</p>
  
  <p>I'm going to use view parameters to make the registration data available
  from the register page to the confirm page, and vice versa.</p>
  
  <p>Supposing there are 20 items of data to be moving from page to page, that's
  a lot of view parameters and a lot of setPropertyActionListeners, especially
  as all the data is going to end up nicely packaged in a User object.</p>
  
  <p>So what I want to do is input the data on the register page into the
  properties of a User record and send a reference to it to the register
  confirm page. What gave me an idea was seeing the BalusC WeakHashMap
  converter. This is a JSF converter which has a static weak hash map and
  generates a uuid as the value for a map entry and the object reference as
  the key. So by specifying this as a converter for f:viewParam you send
  the uuid in the query string.</p>
  
  <p>This works fine. The issue I have is that on the register page I have to
  get an instance of a User class with new. Then I can do:</p>
  
  <pre><code>&lt;h:inputText value="#{bean.user.firstname}"/&gt;
  </code></pre>
  
  <p>(etc...), and pass the user instance as a view parameter. It works fine from
  the register to the confirm page. The issue is that when I perform the
  reverse, sending the user reference back to the register page from the
  confirm page I absolutely cannot prevent the register page backing bean
  from re-instantiating the user object, <strong>after</strong> the setter has been called
  as a result of the view parameter.</p>
  
  <p>So the converter does it's job and retrieves the User object from the
  hash map, calls setUser() in the backing bean, and then I see the
  constructor for the User class firing.</p>
  
  <p>I've tried calling new User() from the bean constructor, in @PostConstruct,
  in a preRenderView (also checking if an ajax request), but nothing I try
  prevents the work of the view parameter from getting wiped out if new is
  involved. I'm sure there's a simple solution but I just can't see it right
  now.</p>
  
  <p>I'd be grateful for any suggestions for how to solve this problem.</p>