Hi,
In the WholeBeanValidator class I encountered the following method:
private Object copyObjectAndPopulateWithCandidateValues(ValueExpression
beanVE,
Object val,
Map<String, Map<String, Object>> candidate) {
// <editor-fold defaultstate="collapsed">
// Populate the value copy with the validated values from the
candidate
Map<String, Object> propertiesToSet = new HashMap<>();
for (Map.Entry<String, Map<String, Object>> cur :
candidate.entrySet()) {
propertiesToSet.put(cur.getKey(), cur.getValue().get("value"));
}
// Copy the value so that class-level validation can be performed
// without corrupting the real value
Object valCopy = null;
try {
NewInstanceCopier nic = new NewInstanceCopier();
valCopy = nic.copy(val);
} catch (IllegalStateException ise2) {
}
if (null == valCopy) {
if (val instanceof Serializable) {
try {
SerializationCopier sc = new SerializationCopier();
valCopy = sc.copy(val);
} catch (IllegalStateException ise) {
}
} else if (val instanceof Cloneable) {
try {
CloneCopier cc = new CloneCopier();
valCopy = cc.copy(val);
} catch (IllegalStateException ise) {
}
} else {
try {
CopyCtorCopier ccc = new CopyCtorCopier();
valCopy = ccc.copy(val);
} catch (IllegalStateException ise) {
}
}
}
As it appears the copy strategy is hard coded here.
In the original OmniFaces code I gave the user the option to set the
strategy. The default is to try a number of strategies (as shown here), but
alternatively the user can either choose an explicit existing strategy
(e.g. CopyCtorCopier), or provide a custom strategy.
This is needed in practice, since with the current implementation it's hard
to make a bean that fails the NewInstanceCopier and still be a bean
(actually, isn't this nearly impossible?).
In other words, if the CopyCtorCopier would be more efficient since the
bean had heavy weight dependencies, then this copier is quite hard now to
actually reach.
I would like to suggest to consider using the same or similar attribute
that OmniFaces uses to set the copier, defaulting to the all strategies one.
Kind regards,
Arjan Tijms