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).
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.
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:
List<UIComponent> createMaterialView = SharedData.findComponent("template_form").getChildren();
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.
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;
}
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.
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?
Thanks! Sorry if that was too verbose. I hope the question is clear.