title: how to let one class inherit values from another class set up via managed bean
body: <p>I am struggling a bit with using one Java class in another class.</p>
  
  <p>For my application I have set up a managed bean for a utility class:</p>
  
  <pre><code>&lt;managed-bean&gt;
      &lt;managed-bean-name&gt;utilBean&lt;/managed-bean-name&gt;
      &lt;managed-bean-class&gt;com.acme.domino.utils.Utils&lt;/managed-bean-class&gt;
      &lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;
      &lt;managed-property&gt;
        &lt;property-name&gt;debug&lt;/property-name&gt;
        &lt;value&gt;false&lt;/value&gt;
        &lt;property-class&gt;java.lang.Boolean&lt;/property-class&gt;
      &lt;/managed-property&gt;    
      &lt;managed-property&gt;
        &lt;property-name&gt;log&lt;/property-name&gt;
        &lt;value&gt;false&lt;/value&gt;
        &lt;property-class&gt;java.lang.Boolean&lt;/property-class&gt;
      &lt;/managed-property&gt;
    &lt;/managed-bean&gt;
  </code></pre>
  
  <p>In this class has a method to write to a log.</p>
  
  <p>Now I would like to use this class in another class. So my thoughts are to inject the managed bean above in another managed bean for the other class.</p>
  
  <pre><code>&lt;managed-bean&gt;
      &lt;managed-bean-name&gt;orderBean&lt;/managed-bean-name&gt;
      &lt;managed-bean-class&gt;com.acme.domino.app.Order&lt;/managed-bean-class&gt;
      &lt;managed-bean-scope&gt;session&lt;/managed-bean-scope&gt;
      &lt;managed-property&gt;
        &lt;property-name&gt;utils&lt;/property-name&gt;
        &lt;value&gt;#{utilsBean}&lt;/value&gt;
      &lt;/managed-property&gt;
    &lt;/managed-bean&gt;
  </code></pre>
  
  <p>The Order class has as field</p>
  
  <pre><code>public Utils utils;
      public Utils getUtils() {
          return utils;
      }
  
      public void setUtils(Utils utils) {
          this.utils = utils;
      }
  </code></pre>
  
  <p>But in the constructor it goes already wrong:</p>
  
  <pre><code>public Order() throws Exception {
          super();
          utils = new Utils();
  
          System.out.println("log?? " + utils.log);
  ..}
  </code></pre>
  
  <p>It seems that in the constructor of the Utils class I have to set the two fields somehow:</p>
  
  <pre><code>public Utils() {
          this.debug = true;
          this.log = true;
  }
  </code></pre>
  
  <p>Within the Utils class the values for the fields are false (as set via the managed properties.</p>
  
  <p>Within the Orders class the values for the fields are true (as set via Utils constructor).</p>
  
  <p>Is there a way to avoid to set the fields in the Utils constructor? Or is there away to avoid to define a new instance of the Utils class within the Order class?</p>
  
  <p>The message that I get when I do not set the fields in the Utils constructor class is:</p>
  
  <p>javax.faces.FacesException: Can't instantiate class: 'com.acme.domino.app.orderBean'.. null
  Can't instantiate class: 'com.acme.domino.app.orderBean'.. null
  class com.acme.domino.app.orderBean : java.lang.NullPointerException</p>
  
  <p>I would like to have that my Order class inherits the settings of the Utils class set via the Managed Bean.</p>