title: overriding a session-scoped Managed Bean with a subclass
body: <p>In a JSF 1.2 application, can I override a session-scoped Managed Bean returned with a subclass?</p>
  
  <p><strong>Class structure</strong></p>
  
  <p>I have a session-scoped Managed Bean, <code>MainViewMB</code>, and its subclass, <code>RestrictedViewMB</code>:</p>
  
  <p><img src="https://yuml.me/551aae24.svg" alt="UML: &lt;&lt;ManagedBean&gt;&gt; MainViewMB extended by RestrictedViewMB"></p>
  
  <p><strong>faces-config.xml</strong></p>
  
  <pre><code>&lt;managed-bean&gt;
    &lt;managed-bean-name&gt;mainViewMB&lt;/managed-bean-name&gt;
    &lt;managed-bean-class&gt;com.example.MainViewMB&lt;/managed-bean-class&gt;
    &lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;
  &lt;/managed-bean&gt;
  </code></pre>
  
  <p><strong>Problem statement</strong></p>
  
  <p>The EL expression <code>#{mainViewMB}</code> returns an instance of <code>MainViewMB</code>.</p>
  
  <p>I would like to rebind the name <code>#{mainViewMB}</code> with an instance of <code>RestrictedViewMB</code>, so that the EL expression <code>#{mainViewMB}</code> returns an instance of the subclass for the rest of the session.</p>
  
  <p>Is there a way to accomplish my goal?</p>
  
  <p><strong>Motivating example</strong></p>
  
  <p><code>MainViewMB</code> handles the GUI logic behind the application's main page. When a user enters the application from a special-purpose login page, I need to provide a restricted, simplified view of the main page. Overriding some of <code>MainViewMB</code>'s properties in a subclass seems the obvious solution.</p>