@@ -0,0 +1,1303 @@
+package ru.ydn.wicket.wicketorientdb.model;%0A%0Aimport org.apache.wicket.model.ChainingModel;%0Aimport org.apache.wicket.model.IDetachable;%0Aimport org.apache.wicket.model.IModel;%0A%0A/**%0A * %7B@link IModel%7D which can dynamically return default value if needed%0A *%0A * @param %3CT%3E the type of model object%0A */%0Apublic class NvlModel%3CT%3E extends ChainingModel%3CT%3E%7B%0A%09%0A%09private Object defaultValue;%0A%09%0A%09public NvlModel(IModel%3CT%3E mainModel, IModel%3CT%3E defaultValueModel) %7B%0A%09%09super(mainModel);%0A%09%09this.defaultValue = defaultValueModel;%0A%09%7D%0A%09%0A%09public NvlModel(IModel%3CT%3E mainModel, T defaultValue) %7B%0A%09%09super(mainModel);%0A%09%09this.defaultValue = defaultValue;%0A%09%7D%0A%09%0A%09@Override%0A%09public T getObject() %7B%0A%09%09T value = super.getObject();%0A%09%09if(isCondition(value)) return value;%0A%09%09else return getDefaultObject();%0A %09%7D%0A%09%0A%09public boolean isCondition(T value) %7B%0A%09%09return value!=null;%0A%09%7D%0A%09%0A%09/**%0A%09 * Returns default value%0A%09 * @return default value%0A%09 */%0A%09@SuppressWarnings(%22unchecked%22)%0A%09public T getDefaultObject() %7B%0A%09%09if(defaultValue instanceof IModel) %7B%0A%09%09%09return ((IModel%3CT%3E)defaultValue).getObject();%0A%09%09%7D else %7B%0A%09%09%09return (T) defaultValue;%0A%09%09%7D%0A%09%7D%0A%09%0A%09@Override%0A%09public void detach()%0A%09%7B%0A%09%09super.detach();%0A%09%09// Detach nested object if it's a detachable%0A%09%09if (defaultValue instanceof IDetachable)%0A%09%09%7B%0A%09%09%09((IDetachable)defaultValue).detach();%0A%09%09%7D%0A%09%7D%0A%7D%0A

Add NvlModel to be able dynamically switch to default model