I have a list of quite detailed objects to compare:
List<MyObject> objectsToCompare;
In the objects there are many fields which could be another Object, String, int, list, etc.
I need to present to the user a table representation of these objects and their fields using JSF like this:
field object1 object2 object3... equal
name fred john george... no
age 26 26 26... yes
Here's what I have planned so far for my JSF page:
<p:panelGrid >
<f:facet name="header">
<p:row>
<p:column>Field</p:column>
<ui:repeat var="loopObject" value="#{compareObjectsBean.objectsForComparison}">
<p:column><h:outputText value="#{loopObject.id}" /></p:column>
</ui:repeat>
<p:column>All Objects Equal</p:column>
</p:row>
</f:facet>
<p:row>
<p:column>Name</p:column>
<ui:repeat var="loopObject" value="#{compareObjectsBean.objectsForComparison}">
<p:column><h:outputText value="#{loopObject.name}" /></p:column>
</ui:repeat>
<p:column><h:outputText value="#{compareObjectsController.namesEqual()?'yes':'no'}"/> </p:column>
</p:row>
<p:row>
<p:column>Age</p:column>
<ui:repeat var="loopObject" value="#{compareObjectsBean.objectsForComparison}">
<p:column><h:outputText value="#{loopObject.age}" /></p:column>
</ui:repeat>
<p:column><h:outputText value="#{compareObjectsController.agesEqual()?'yes':'no'}"/> </p:column>
</p:row>
and for example in the compareObjectsController is a comparison method for each field:
public boolean namesEqual(){
String firstObjectName = compareObjectsBean.getObjectsForComparison().get(0).getName();
for(int i = 1; i< compareObjectsBean.getObjectsForComparison().size(); i++){
if(!compareObjectsBean.getObjectsForComparison().get(i).getName().equals(firstObjectName)){
return false;
}
}
return true;//all matched the first, so all are equal
}
This doesn't seem very efficient, especially when the objects being compared have approx 300 fields (includes fields of objects belonging to MyObject).
How can I optimise/optimize this so that I do not need to write ~300 comparison methods in the controller, and possibly also ~300 rows?
Note: I am also using primefaces, but this could just be a simple table.