title: Storing (and retrieving) references to dynamically / programmatically created form objects - Are UIComponents NOT passed by reference?
body: <p>I am writing a program for a content management system that creates a form based on the contents of a given XML. The XML has has information about the structure of the content (comes from dropdown) to be created and the input types (text area for paragraph, textfield for chapter title, etc.) associated with each leaf. I shall call this a 'fragment'. A fragment can either be a leaf (textbox, text area, etc. - holding sentences / paragraphs) or a Node (which has other fragments inside it).</p>
  
  <p>I want to confirm that any newly created fragment(s) in a material don't previously exist. For this, I will need to know what fragment type (is it a chapter title, chapter summary, etc.) it is so that I can query the database to find out if the current fragment is a duplicate, based on content.</p>
  
  <p>I tried to save a reference to the dynamically created component object in an ArrayList. This arraylist has fragment type, for every input component created. In my bean, I call:</p>
  
  <pre><code>List&lt;UIComponent&gt; createMaterialView =  SharedData.findComponent("template_form").getChildren();
  </code></pre>
  
  <p>and recursively step through the children that are in createMaterialView, none of the UIComponents that are processed in the form are matching the UIComponents I added into my ArrayList earlier.</p>
  
  <pre><code>private FragmentTypeLeaf getFragmentTypeIfLeaf(UIComponent component) {
      System.out.println("Checking if "+component+" of class:"+component.getClass()+" is in LeafFrags");
      for(FragmentTypeLeaf currentLeaf : leafFragments) {
        if(component.equals(currentLeaf.getInputComponent())) {
            //Found leaf fragment input panel.
            System.out.println("Found a leaf fragment:"+currentLeaf.getName()+",Type:"+currentLeaf.getFragmentType());
            return currentLeaf;
            //Validate this content with all fragments existing (of this type) to ensure not exist.
        }
      }
      return null;
  }
  </code></pre>
  
  <p>I did console outputs for UIComponent.toString() when I created them and added them to the form + leafFragments, and compared them to he component.toString in the getFragmentTypeIfLeaf() pasted below. I see that though the expected classes match, the UIComponents don't.</p>
  
  <p>Are UIComponents not passed by reference? If I cannot create the UIComponent, add it to the form + track its reference by adding it to a list, then how can I design a system that can check if a dynamically created UIComponent (which needs to be associated with a fragment type) has content that already exists for that fragment type in the database?</p>
  
  <p>Thanks! Sorry if that was too verbose. I hope the question is clear.</p>