Seitenhistorie
...
PS: Wie man es richtig macht, kann man hier sehen: Das Beispiel für schlechte Programmierung wie Wie man es richtig macht:
private void setFieldInitial(CollectableField clctfValue) {
CollectableField cf = clctfValue;
if (getValueListProvider() != null && cf != null) {
CollectableFieldsProvider vlp = getValueListProvider();
if (vlp instanceof CachingCollectableFieldsProvider) {
vlp = ((CachingCollectableFieldsProvider)vlp).getDelegate();
}
if (vlp instanceof DatasourceBasedCollectableFieldsProvider) {
try {
if (getValueListProvider() instanceof CachingCollectableFieldsProvider) {
cf = CollectionUtils.getSingleIfExist(((CachingCollectableFieldsProvider)getValueListProvider())
.getCollectableFields(Collections.singletonList(IdUtils.unsafeToId(clctfValue.getValueId()))));
} else {
cf = CollectionUtils.getSingleIfExist(((DatasourceBasedCollectableFieldsProvider)vlp)
.getCollectableFields(Collections.singletonList(IdUtils.unsafeToId(clctfValue.getValueId()))));
}
if (cf == null)
cf = clctfValue;
} catch (IllegalArgumentException e) {
// ignore here. VLP has no id or value column set.
} catch (Exception e) {
throw new NuclosFatalException(e);
}
}
}
getModel().setFieldInitial(cf);
}
@Override
public void setField(CollectableField clctfValue) {
CollectableField cf = clctfValue;
if (getValueListProvider() != null && cf != null) {
CollectableFieldsProvider vlp = getValueListProvider();
if (vlp instanceof CachingCollectableFieldsProvider) {
vlp = ((CachingCollectableFieldsProvider)vlp).getDelegate();
}
if (vlp instanceof DatasourceBasedCollectableFieldsProvider) {
try {
if (getValueListProvider() instanceof CachingCollectableFieldsProvider) {
cf = CollectionUtils.getSingleIfExist(((CachingCollectableFieldsProvider)getValueListProvider())
.getCollectableFields(Collections.singletonList(IdUtils.unsafeToId(clctfValue.getValueId()))));
} else {
cf = CollectionUtils.getSingleIfExist(((DatasourceBasedCollectableFieldsProvider)vlp)
.getCollectableFields(Collections.singletonList(IdUtils.unsafeToId(clctfValue.getValueId()))));
}
if (cf == null)
cf = clctfValue;
} catch (IllegalArgumentException e) {
// ignore here. VLP has no id or value column set.
} catch (Exception e) {
throw new NuclosFatalException(e);
}
}
}
super.setField(cf);
}
Überblick
Inhalte