[+] on proposition shadow

On Tue, Nov 18, 2008 at 4:16 PM, Nino Saturnino Martinez Vazquez Wael <
[EMAIL PROTECTED]> wrote:

> And heres the result in all its glory, should I create jira issue and
> attach the code?.. :
>
> package zeuzgroup.web.model;
>
> import java.lang.reflect.Field;
> import java.lang.reflect.Method;
> import java.util.HashMap;
> import java.util.Map;
> import java.util.Map.Entry;
>
> import org.apache.wicket.Application;
> import org.apache.wicket.Component;
> import org.apache.wicket.Session;
> import org.apache.wicket.WicketRuntimeException;
> import org.apache.wicket.model.AbstractPropertyModel;
> import org.apache.wicket.model.CompoundPropertyModel;
> import org.apache.wicket.model.IModel;
> import org.apache.wicket.model.IWrapModel;
> import org.apache.wicket.util.lang.PropertyResolver;
> import org.apache.wicket.util.lang.PropertyResolverConverter;
>
> public class ShadowCompoundPropertyModel<T> extends
> CompoundPropertyModel<T> {
>
>   private final Map<String, Object> newValues = new HashMap<String,
> Object>();
>
>   public ShadowCompoundPropertyModel(IModel<T> underlyingModel) {
>       super(underlyingModel);
>   }
>
>   public void fillOriginal() {
>       for (Entry<String, Object> entry : newValues.entrySet()) {
>
>               PropertyResolverConverter prc = null;
>               prc = new
> PropertyResolverConverter(Application.get().getConverterLocator(),
>                   Session.get().getLocale());
>               PropertyResolver.setValue(entry.getKey(), getObject(),
> entry.getValue(), prc);
>       }
>   }
>
>   public <C> IWrapModel<C> wrapOnInheritance(Component component) {
>       return new AttachedCompoundPropertyModel<C>(component, newValues);
>   }
>
>   private class AttachedCompoundPropertyModel<C> extends
>           AbstractPropertyModel<C> implements IWrapModel<C> {
>       private static final long serialVersionUID = 1L;
>
>       private final Component owner;
>
>       private final Map<String, Object> newValues;
>
>       /**
>        * Constructor
>        *
>        * @param owner
>        *            component that this model has been attached to
>        */
>       public AttachedCompoundPropertyModel(Component owner,
>               Map<String, Object> map) {
>           super(ShadowCompoundPropertyModel.this);
>           this.owner = owner;
>           this.newValues = map;
>       }
>
>       @Override
>       public C getObject() {
>           if
> (ShadowCompoundPropertyModel.this.newValues.containsKey(owner.getId())) {
>               return (C) newValues.get(owner.getId());
>           } else {
>               return super.getObject();
>           }
>       }
>
>       @Override
>       public void setObject(C object) {
>           newValues.put(owner.getId(), object);
>       }
>
>       /**
>        * @see
> org.apache.wicket.model.AbstractPropertyModel#propertyExpression()
>        */
>       @Override
>       protected String propertyExpression() {
>           return
> ShadowCompoundPropertyModel.this.propertyExpression(owner);
>       }
>
>       /**
>        * @see org.apache.wicket.model.IWrapModel#getWrappedModel()
>        */
>       public IModel<T> getWrappedModel() {
>           return ShadowCompoundPropertyModel.this;
>       }
>
>       /**
>        * @see org.apache.wicket.model.AbstractPropertyModel#detach()
>        */
>       @Override
>       public void detach() {
>           super.detach();
>           ShadowCompoundPropertyModel.this.detach();
>       }
>   }
>
> }
>
> // IComponentAssignedModel / IWrapModel
>
>
> Nino Saturnino Martinez Vazquez Wael wrote:
>
>> Hi
>>
>> Im trying todo a compoundpropertymodel which does not change original
>> values in the "original" model. I need this since I am updating some stuff
>> in a wizard but I first want to commit when the user confirms in the end of
>> the wizard, and if the model are changed directly the transaction are
>> automatically committed to the database....
>>
>> So my idea were to todo a shadowCompoundPropertyModel something like this:
>>
>> class EditorModel extends CompoundPropertyModel {
>>     private Map newValues=new HashMap<String, Object>();
>>     public EditorModel(CompoundPropertyModel underlyingModel,
>>           String propertyName) {
>>       super(underlyingModel);
>>   }
>>  public getObject (String property){
>> check if there are something in the map if so return it, otherwise fall
>> back to the underlying model
>>
>> }  public setObject (String prop, Value){
>>   put changes in the map...
>> }
>>
>> public UpdateOriginal(){
>> iterate over the map and use reflection to set values on the original
>> model..
>>
>> }
>>
>> }
>>
>> Does anybody have something similar floating around, in a more complete
>> state..? Or could it be done in a easier way?
>>
>>
> --
> -Wicket for love
>
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

Reply via email to