You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk> on 2008/11/18 13:43:44 UTC
Compoundpropertymodel with shadow map?
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
True, this is also what I am thinking about doing...
Johan Compagner wrote:
> If you dont want to use an original object why not just clone/create a
> copy of the original end use that and then copy the values over again?
> (i think beanutils or something van do that for you)
>
> On 11/18/08, Nino Saturnino Martinez Vazquez Wael
> <ni...@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
-Wicket for love
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Johan Compagner <jc...@gmail.com>.
If you dont want to use an original object why not just clone/create a
copy of the original end use that and then copy the values over again?
(i think beanutils or something van do that for you)
On 11/18/08, Nino Saturnino Martinez Vazquez Wael
<ni...@jayway.dk> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Ok great.. Seems like SerializationHelper.clone and just a normal
compound model could work..
Francisco Diaz Trepat - gmail wrote:
> Don't know, but LOL.
> This might be an instancing issue in which special handling is good for this
> scenario but seems to be fine for most cases. And in a lazy TDD programming
> way it might be good enough.
>
> Although I know from blog and other threads that you look for greatness :-)
> and not just code that works. Which is very inspiring now a days, in this
> business hour of programming history.
>
> I'll ask arround though, I think I might know someone who might know, and
> also is not my mother...
>
> f(t)
>
> On Thu, Nov 20, 2008 at 6:26 PM, Nino Saturnino Martinez Vazquez Wael <
> nino.martinez@jayway.dk> wrote:
>
>
>> I love simple and simple is good. But this approach has issues with
>> hibernate if your hibernate sessions are per request and your shadowmodel
>> lives in multiple requests and your entities has references to other
>> entities for example 1..* etc ... In "simple" use cases, and possibly also
>> when not using hibernate this might be fine. This is what I am exploring
>> currently. When not attending seminars or talking with people..
>>
>> Im wondering how eclipselink & openJPA handles the "hibernate lazy load
>> problem", according to a oracle guy theres not a problem when using Toplink
>> (which now are eclipselink?)
>>
>> Input on these things are very welcome...
>>
>> regards Nino
>>
>>
>> Francisco Diaz Trepat - gmail wrote:
>>
>>
>>> why?
>>> simple is good. doesn't need to be complex.
>>>
>>> what part you dislike the most?
>>>
>>> f(t)
>>>
>>> On Thu, Nov 20, 2008 at 2:29 AM, Nino Saturnino Martinez Vazquez Wael <
>>> nino.martinez@jayway.dk> wrote:
>>>
>>>
>>>
>>>
>>>> BTW this is a flawed approch.. We need something a little more
>>>> intelligent.. I'll return on the subject..
>>>>
>>>>
>>>> Nino Saturnino Martinez Vazquez Wael wrote:
>>>>
>>>>
>>>>
>>>>
>>>>> heres the raw and completely untested version of it. probably with a
>>>>> whole
>>>>> bunch of issues...:
>>>>>
>>>>> package zeuzgroup.web.model;
>>>>> import java.lang.reflect.Field;
>>>>> import java.util.HashMap;
>>>>> import java.util.Map;
>>>>> import java.util.Map.Entry;
>>>>> import org.apache.wicket.Component;
>>>>> 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;
>>>>> public class EditorModel<T> extends CompoundPropertyModel<T> {
>>>>> private final Map<String, Object> newValues = new HashMap<String,
>>>>> Object>();
>>>>> public EditorModel(IModel<T> underlyingModel) {
>>>>> super(underlyingModel);
>>>>> }
>>>>> public void fillOriginal() {
>>>>> Class<?> c = this.getObject().getClass();
>>>>> for (Entry<String, Object> entry : newValues.entrySet()) {
>>>>> try {
>>>>> Field t = c.getDeclaredField(entry.getKey());
>>>>> t.set(this.getObject(), entry.getValue());
>>>>> } catch (Exception e) {
>>>>> throw new WicketRuntimeException("Could not set "
>>>>> + entry.getKey(), e);
>>>>> }
>>>>> }
>>>>> }
>>>>> 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(EditorModel.this);
>>>>> this.owner = owner;
>>>>> this.newValues = map;
>>>>> }
>>>>> @Override
>>>>> public C getObject() {
>>>>> if (EditorModel.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 EditorModel.this.propertyExpression(owner);
>>>>> }
>>>>> /**
>>>>> * @see org.apache.wicket.model.IWrapModel#getWrappedModel()
>>>>> */
>>>>> public IModel<T> getWrappedModel() {
>>>>> return EditorModel.this;
>>>>> }
>>>>> /**
>>>>> * @see org.apache.wicket.model.AbstractPropertyModel#detach()
>>>>> */
>>>>> @Override
>>>>> public void detach() {
>>>>> super.detach();
>>>>> EditorModel.this.detach();
>>>>> }
>>>>> }
>>>>> }
>>>>> // IComponentAssignedModel / IWrapModel
>>>>>
>>>>> Francisco Diaz Trepat - gmail wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> Nice, I was up to something similar.
>>>>>>
>>>>>> On Tue, Nov 18, 2008 at 9:43 AM, Nino Saturnino Martinez Vazquez Wael <
>>>>>> nino.martinez@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>> --
>>>> -Wicket for love
>>>>
>>>> Nino Martinez Wael
>>>> Java Specialist @ Jayway DK
>>>> http://www.jayway.dk
>>>> +45 2936 7684
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>> --
>> -Wicket for love
>>
>> Nino Martinez Wael
>> Java Specialist @ Jayway DK
>> http://www.jayway.dk
>> +45 2936 7684
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
>
--
-Wicket for love
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Francisco Diaz Trepat - gmail <fr...@gmail.com>.
Don't know, but LOL.
This might be an instancing issue in which special handling is good for this
scenario but seems to be fine for most cases. And in a lazy TDD programming
way it might be good enough.
Although I know from blog and other threads that you look for greatness :-)
and not just code that works. Which is very inspiring now a days, in this
business hour of programming history.
I'll ask arround though, I think I might know someone who might know, and
also is not my mother...
f(t)
On Thu, Nov 20, 2008 at 6:26 PM, Nino Saturnino Martinez Vazquez Wael <
nino.martinez@jayway.dk> wrote:
> I love simple and simple is good. But this approach has issues with
> hibernate if your hibernate sessions are per request and your shadowmodel
> lives in multiple requests and your entities has references to other
> entities for example 1..* etc ... In "simple" use cases, and possibly also
> when not using hibernate this might be fine. This is what I am exploring
> currently. When not attending seminars or talking with people..
>
> Im wondering how eclipselink & openJPA handles the "hibernate lazy load
> problem", according to a oracle guy theres not a problem when using Toplink
> (which now are eclipselink?)
>
> Input on these things are very welcome...
>
> regards Nino
>
>
> Francisco Diaz Trepat - gmail wrote:
>
>> why?
>> simple is good. doesn't need to be complex.
>>
>> what part you dislike the most?
>>
>> f(t)
>>
>> On Thu, Nov 20, 2008 at 2:29 AM, Nino Saturnino Martinez Vazquez Wael <
>> nino.martinez@jayway.dk> wrote:
>>
>>
>>
>>> BTW this is a flawed approch.. We need something a little more
>>> intelligent.. I'll return on the subject..
>>>
>>>
>>> Nino Saturnino Martinez Vazquez Wael wrote:
>>>
>>>
>>>
>>>> heres the raw and completely untested version of it. probably with a
>>>> whole
>>>> bunch of issues...:
>>>>
>>>> package zeuzgroup.web.model;
>>>> import java.lang.reflect.Field;
>>>> import java.util.HashMap;
>>>> import java.util.Map;
>>>> import java.util.Map.Entry;
>>>> import org.apache.wicket.Component;
>>>> 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;
>>>> public class EditorModel<T> extends CompoundPropertyModel<T> {
>>>> private final Map<String, Object> newValues = new HashMap<String,
>>>> Object>();
>>>> public EditorModel(IModel<T> underlyingModel) {
>>>> super(underlyingModel);
>>>> }
>>>> public void fillOriginal() {
>>>> Class<?> c = this.getObject().getClass();
>>>> for (Entry<String, Object> entry : newValues.entrySet()) {
>>>> try {
>>>> Field t = c.getDeclaredField(entry.getKey());
>>>> t.set(this.getObject(), entry.getValue());
>>>> } catch (Exception e) {
>>>> throw new WicketRuntimeException("Could not set "
>>>> + entry.getKey(), e);
>>>> }
>>>> }
>>>> }
>>>> 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(EditorModel.this);
>>>> this.owner = owner;
>>>> this.newValues = map;
>>>> }
>>>> @Override
>>>> public C getObject() {
>>>> if (EditorModel.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 EditorModel.this.propertyExpression(owner);
>>>> }
>>>> /**
>>>> * @see org.apache.wicket.model.IWrapModel#getWrappedModel()
>>>> */
>>>> public IModel<T> getWrappedModel() {
>>>> return EditorModel.this;
>>>> }
>>>> /**
>>>> * @see org.apache.wicket.model.AbstractPropertyModel#detach()
>>>> */
>>>> @Override
>>>> public void detach() {
>>>> super.detach();
>>>> EditorModel.this.detach();
>>>> }
>>>> }
>>>> }
>>>> // IComponentAssignedModel / IWrapModel
>>>>
>>>> Francisco Diaz Trepat - gmail wrote:
>>>>
>>>>
>>>>
>>>>> Nice, I was up to something similar.
>>>>>
>>>>> On Tue, Nov 18, 2008 at 9:43 AM, Nino Saturnino Martinez Vazquez Wael <
>>>>> nino.martinez@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>> --
>>> -Wicket for love
>>>
>>> Nino Martinez Wael
>>> Java Specialist @ Jayway DK
>>> http://www.jayway.dk
>>> +45 2936 7684
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>>
>>
>>
>>
>
> --
> -Wicket for love
>
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Compoundpropertymodel with shadow map?
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
I love simple and simple is good. But this approach has issues with
hibernate if your hibernate sessions are per request and your
shadowmodel lives in multiple requests and your entities has references
to other entities for example 1..* etc ... In "simple" use cases, and
possibly also when not using hibernate this might be fine. This is what
I am exploring currently. When not attending seminars or talking with
people..
Im wondering how eclipselink & openJPA handles the "hibernate lazy load
problem", according to a oracle guy theres not a problem when using
Toplink (which now are eclipselink?)
Input on these things are very welcome...
regards Nino
Francisco Diaz Trepat - gmail wrote:
> why?
> simple is good. doesn't need to be complex.
>
> what part you dislike the most?
>
> f(t)
>
> On Thu, Nov 20, 2008 at 2:29 AM, Nino Saturnino Martinez Vazquez Wael <
> nino.martinez@jayway.dk> wrote:
>
>
>> BTW this is a flawed approch.. We need something a little more
>> intelligent.. I'll return on the subject..
>>
>>
>> Nino Saturnino Martinez Vazquez Wael wrote:
>>
>>
>>> heres the raw and completely untested version of it. probably with a whole
>>> bunch of issues...:
>>>
>>> package zeuzgroup.web.model;
>>> import java.lang.reflect.Field;
>>> import java.util.HashMap;
>>> import java.util.Map;
>>> import java.util.Map.Entry;
>>> import org.apache.wicket.Component;
>>> 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;
>>> public class EditorModel<T> extends CompoundPropertyModel<T> {
>>> private final Map<String, Object> newValues = new HashMap<String,
>>> Object>();
>>> public EditorModel(IModel<T> underlyingModel) {
>>> super(underlyingModel);
>>> }
>>> public void fillOriginal() {
>>> Class<?> c = this.getObject().getClass();
>>> for (Entry<String, Object> entry : newValues.entrySet()) {
>>> try {
>>> Field t = c.getDeclaredField(entry.getKey());
>>> t.set(this.getObject(), entry.getValue());
>>> } catch (Exception e) {
>>> throw new WicketRuntimeException("Could not set "
>>> + entry.getKey(), e);
>>> }
>>> }
>>> }
>>> 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(EditorModel.this);
>>> this.owner = owner;
>>> this.newValues = map;
>>> }
>>> @Override
>>> public C getObject() {
>>> if (EditorModel.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 EditorModel.this.propertyExpression(owner);
>>> }
>>> /**
>>> * @see org.apache.wicket.model.IWrapModel#getWrappedModel()
>>> */
>>> public IModel<T> getWrappedModel() {
>>> return EditorModel.this;
>>> }
>>> /**
>>> * @see org.apache.wicket.model.AbstractPropertyModel#detach()
>>> */
>>> @Override
>>> public void detach() {
>>> super.detach();
>>> EditorModel.this.detach();
>>> }
>>> }
>>> }
>>> // IComponentAssignedModel / IWrapModel
>>>
>>> Francisco Diaz Trepat - gmail wrote:
>>>
>>>
>>>> Nice, I was up to something similar.
>>>>
>>>> On Tue, Nov 18, 2008 at 9:43 AM, Nino Saturnino Martinez Vazquez Wael <
>>>> nino.martinez@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>> --
>> -Wicket for love
>>
>> Nino Martinez Wael
>> Java Specialist @ Jayway DK
>> http://www.jayway.dk
>> +45 2936 7684
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
>
--
-Wicket for love
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Francisco Diaz Trepat - gmail <fr...@gmail.com>.
why?
simple is good. doesn't need to be complex.
what part you dislike the most?
f(t)
On Thu, Nov 20, 2008 at 2:29 AM, Nino Saturnino Martinez Vazquez Wael <
nino.martinez@jayway.dk> wrote:
> BTW this is a flawed approch.. We need something a little more
> intelligent.. I'll return on the subject..
>
>
> Nino Saturnino Martinez Vazquez Wael wrote:
>
>> heres the raw and completely untested version of it. probably with a whole
>> bunch of issues...:
>>
>> package zeuzgroup.web.model;
>> import java.lang.reflect.Field;
>> import java.util.HashMap;
>> import java.util.Map;
>> import java.util.Map.Entry;
>> import org.apache.wicket.Component;
>> 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;
>> public class EditorModel<T> extends CompoundPropertyModel<T> {
>> private final Map<String, Object> newValues = new HashMap<String,
>> Object>();
>> public EditorModel(IModel<T> underlyingModel) {
>> super(underlyingModel);
>> }
>> public void fillOriginal() {
>> Class<?> c = this.getObject().getClass();
>> for (Entry<String, Object> entry : newValues.entrySet()) {
>> try {
>> Field t = c.getDeclaredField(entry.getKey());
>> t.set(this.getObject(), entry.getValue());
>> } catch (Exception e) {
>> throw new WicketRuntimeException("Could not set "
>> + entry.getKey(), e);
>> }
>> }
>> }
>> 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(EditorModel.this);
>> this.owner = owner;
>> this.newValues = map;
>> }
>> @Override
>> public C getObject() {
>> if (EditorModel.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 EditorModel.this.propertyExpression(owner);
>> }
>> /**
>> * @see org.apache.wicket.model.IWrapModel#getWrappedModel()
>> */
>> public IModel<T> getWrappedModel() {
>> return EditorModel.this;
>> }
>> /**
>> * @see org.apache.wicket.model.AbstractPropertyModel#detach()
>> */
>> @Override
>> public void detach() {
>> super.detach();
>> EditorModel.this.detach();
>> }
>> }
>> }
>> // IComponentAssignedModel / IWrapModel
>>
>> Francisco Diaz Trepat - gmail wrote:
>>
>>> Nice, I was up to something similar.
>>>
>>> On Tue, Nov 18, 2008 at 9:43 AM, Nino Saturnino Martinez Vazquez Wael <
>>> nino.martinez@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
> --
> -Wicket for love
>
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Compoundpropertymodel with shadow map?
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
BTW this is a flawed approch.. We need something a little more
intelligent.. I'll return on the subject..
Nino Saturnino Martinez Vazquez Wael wrote:
> heres the raw and completely untested version of it. probably with a
> whole bunch of issues...:
>
> package zeuzgroup.web.model;
> import java.lang.reflect.Field;
> import java.util.HashMap;
> import java.util.Map;
> import java.util.Map.Entry;
> import org.apache.wicket.Component;
> 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;
> public class EditorModel<T> extends CompoundPropertyModel<T> {
> private final Map<String, Object> newValues = new
> HashMap<String, Object>();
> public EditorModel(IModel<T> underlyingModel) {
> super(underlyingModel);
> }
> public void fillOriginal() {
> Class<?> c = this.getObject().getClass();
> for (Entry<String, Object> entry : newValues.entrySet()) {
> try {
> Field t = c.getDeclaredField(entry.getKey());
> t.set(this.getObject(), entry.getValue());
> } catch (Exception e) {
> throw new WicketRuntimeException("Could not set "
> + entry.getKey(), e);
> }
> }
> }
> 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(EditorModel.this);
> this.owner = owner;
> this.newValues = map;
> }
> @Override
> public C getObject() {
> if
> (EditorModel.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 EditorModel.this.propertyExpression(owner);
> }
> /**
> * @see org.apache.wicket.model.IWrapModel#getWrappedModel()
> */
> public IModel<T> getWrappedModel() {
> return EditorModel.this;
> }
> /**
> * @see org.apache.wicket.model.AbstractPropertyModel#detach()
> */
> @Override
> public void detach() {
> super.detach();
> EditorModel.this.detach();
> }
> }
> }
> // IComponentAssignedModel / IWrapModel
>
> Francisco Diaz Trepat - gmail wrote:
>> Nice, I was up to something similar.
>>
>> On Tue, Nov 18, 2008 at 9:43 AM, Nino Saturnino Martinez Vazquez Wael <
>> nino.martinez@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>>
>
--
-Wicket for love
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
heres the raw and completely untested version of it. probably with a
whole bunch of issues...:
package zeuzgroup.web.model;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.wicket.Component;
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;
public class EditorModel<T> extends CompoundPropertyModel<T> {
private final Map<String, Object> newValues = new
HashMap<String, Object>();
public EditorModel(IModel<T> underlyingModel) {
super(underlyingModel);
}
public void fillOriginal() {
Class<?> c = this.getObject().getClass();
for (Entry<String, Object> entry : newValues.entrySet()) {
try {
Field t = c.getDeclaredField(entry.getKey());
t.set(this.getObject(), entry.getValue());
} catch (Exception e) {
throw new WicketRuntimeException("Could not set "
+ entry.getKey(), e);
}
}
}
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(EditorModel.this);
this.owner = owner;
this.newValues = map;
}
@Override
public C getObject() {
if (EditorModel.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 EditorModel.this.propertyExpression(owner);
}
/**
* @see org.apache.wicket.model.IWrapModel#getWrappedModel()
*/
public IModel<T> getWrappedModel() {
return EditorModel.this;
}
/**
* @see org.apache.wicket.model.AbstractPropertyModel#detach()
*/
@Override
public void detach() {
super.detach();
EditorModel.this.detach();
}
}
}
// IComponentAssignedModel / IWrapModel
Francisco Diaz Trepat - gmail wrote:
> Nice, I was up to something similar.
>
> On Tue, Nov 18, 2008 at 9:43 AM, Nino Saturnino Martinez Vazquez Wael <
> nino.martinez@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
>
--
-Wicket for love
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Francisco Diaz Trepat - gmail <fr...@gmail.com>.
Nice, I was up to something similar.
On Tue, Nov 18, 2008 at 9:43 AM, Nino Saturnino Martinez Vazquez Wael <
nino.martinez@jayway.dk> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Compoundpropertymodel with shadow map?
Posted by Francisco Diaz Trepat - gmail <fr...@gmail.com>.
[+] on proposition shadow
On Tue, Nov 18, 2008 at 4:16 PM, Nino Saturnino Martinez Vazquez Wael <
nino.martinez@jayway.dk> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Compoundpropertymodel with shadow map?
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
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: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Francisco Diaz Trepat - gmail <fr...@gmail.com>.
Shadows sounds good... :-)f(t)
On Tue, Nov 18, 2008 at 11:37 AM, James Carman
<ja...@carmanconsulting.com>wrote:
> You could adapt the proxy model thing (I kind of like the name
> "shadow" and I might change mine) to do what you want. You'd need to
> keep a flag that tells whether or not you've retrieved the value from
> the "destination" model.
>
> On Tue, Nov 18, 2008 at 9:33 AM, Nino Saturnino Martinez Vazquez Wael
> <ni...@jayway.dk> wrote:
> > I do.. But if I use it with a detachable model the idea goes a bit away..
> > Plus I'd like it to be a bit more transparent... Could be me that just
> not
> > know enough....
> >
> > James Carman wrote:
> >>
> >> You didn't like the ProxyModelManager?
> >>
> >>
> >>
> https://wicketopia.svn.sourceforge.net/svnroot/wicketopia/trunk/wicketopia/src/main/java/org/wicketopia/model/proxy/ProxyModelManager.java
> >>
> >>
> >>
> >> On Tue, Nov 18, 2008 at 7:43 AM, Nino Saturnino Martinez Vazquez Wael
> >> <ni...@jayway.dk> 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: users-unsubscribe@wicket.apache.org
> >>> For additional commands, e-mail: users-help@wicket.apache.org
> >>>
> >>>
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> >> For additional commands, e-mail: users-help@wicket.apache.org
> >>
> >>
> >
> > --
> > -Wicket for love
> >
> > Nino Martinez Wael
> > Java Specialist @ Jayway DK
> > http://www.jayway.dk
> > +45 2936 7684
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: Compoundpropertymodel with shadow map?
Posted by James Carman <ja...@carmanconsulting.com>.
You could adapt the proxy model thing (I kind of like the name
"shadow" and I might change mine) to do what you want. You'd need to
keep a flag that tells whether or not you've retrieved the value from
the "destination" model.
On Tue, Nov 18, 2008 at 9:33 AM, Nino Saturnino Martinez Vazquez Wael
<ni...@jayway.dk> wrote:
> I do.. But if I use it with a detachable model the idea goes a bit away..
> Plus I'd like it to be a bit more transparent... Could be me that just not
> know enough....
>
> James Carman wrote:
>>
>> You didn't like the ProxyModelManager?
>>
>>
>> https://wicketopia.svn.sourceforge.net/svnroot/wicketopia/trunk/wicketopia/src/main/java/org/wicketopia/model/proxy/ProxyModelManager.java
>>
>>
>>
>> On Tue, Nov 18, 2008 at 7:43 AM, Nino Saturnino Martinez Vazquez Wael
>> <ni...@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
> --
> -Wicket for love
>
> Nino Martinez Wael
> Java Specialist @ Jayway DK
> http://www.jayway.dk
> +45 2936 7684
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
I do.. But if I use it with a detachable model the idea goes a bit
away.. Plus I'd like it to be a bit more transparent... Could be me that
just not know enough....
James Carman wrote:
> You didn't like the ProxyModelManager?
>
> https://wicketopia.svn.sourceforge.net/svnroot/wicketopia/trunk/wicketopia/src/main/java/org/wicketopia/model/proxy/ProxyModelManager.java
>
>
>
> On Tue, Nov 18, 2008 at 7:43 AM, Nino Saturnino Martinez Vazquez Wael
> <ni...@jayway.dk> 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: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
--
-Wicket for love
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Compoundpropertymodel with shadow map?
Posted by James Carman <ja...@carmanconsulting.com>.
You didn't like the ProxyModelManager?
https://wicketopia.svn.sourceforge.net/svnroot/wicketopia/trunk/wicketopia/src/main/java/org/wicketopia/model/proxy/ProxyModelManager.java
On Tue, Nov 18, 2008 at 7:43 AM, Nino Saturnino Martinez Vazquez Wael
<ni...@jayway.dk> 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: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org