lol

On 4/5/07, Johan Compagner <[EMAIL PROTECTED]> wrote:
All these idea's are ofcourse not mine but matej's!

johan

P.S. return PropertyResolver.getValue(propertyName,
component.getParent().getModel().getObject());

        should be i guess
      return PropertyResolver.getValue(propertyName, component.getParent
().getInnerMostModel().getObject());

On 4/5/07, Johan Compagner <[EMAIL PROTECTED]> wrote:
>
> That one really doesn't work if i understand correctly what it should do
>
> i guess it should do this:
>
> Form form = new Form(new CompoundModel(new Person))l
> form.add(new TextField(new ComponentPropertyModel("name")))
>
> and then it should get name of the person of the compound?
>
> that really doesn't work with the current implementation.
> And it will never work in the current setup Because how do you get from
> the textfields.setModel (that sets the componentpropertymodel)
> to the forms model where the data is in? This can only be done with some
> kind of hack
> currently this is the code:
>
> AssignmentWrapper(final Component component, final String propertyName)
>
>         /**
>          * @see wicket.model.INestedModelContainer#getNestedModel()
>          */
>         public IModel getNestedModel()
>         {
>             return component.getModel();
>         }
>
> And this piece of code is really wrong. the getNestedModel should return
> the parent model of the current model
> and that is not the component.getModel() because that is the
> assigmentwrapper it self!
>
> then
>         public Object getObject()
>         {
>             return PropertyResolver.getValue(propertyName,
> component.getInnermostModel()
>                     .getObject());
>         }
>
>
> component.getInnermodelModel () will throw an exception:
>
> IModel nested = model;
>         while (nested != null && nested instanceof INestedModelContainer)
>         {
>             final IModel next =
> ((INestedModelContainer)nested).getNestedModel();
>             if (nested == next)
>             {
>                 throw new WicketRuntimeException("Model for " + nested + "
> is self-referential");
>
>
>
> because the first nested model == AssigmentWrapper which does
> getNestedModel which does component.getModel() which is again
> assigmentwrapper
>
> what you really want is this:
>
> public Object getObject()
>         {
>             return PropertyResolver.getValue(propertyName,
> component.getParent().getModel().getObject());
>         }
>
>
> so by pass the component and go straight to its parent
>
> so AssignmentWrapper will be then this:
>
> static private class AssignmentWrapper extends AbstractReadOnlyModel
>             implements
>                 INestedModelContainer
>     {
>         private static final long serialVersionUID = 1L;
>
>         private final Component component;
>
>         private final String propertyName;
>
>         AssignmentWrapper(final Component component, final String
> propertyName)
>         {
>             this.component = component;
>             this.propertyName = propertyName;
>         }
>
>         /**
>          * @see wicket.model.INestedModelContainer#getNestedModel()
>          */
>         public IModel getNestedModel()
>         {
>             return ComponentPropertyModel.this;
>         }
>
>         protected String propertyExpression()
>         {
>             return propertyName;
>         }
>
>         public Object getObject()
>         {
>             return PropertyResolver.getValue(propertyName,
> component.getParent().getModel().getObject());
>         }
>     }
>
> then it should work.
>
> But why do we need this model? this doesn't really save anything or add
> anything
> you still have to do this:
>
> Form form = new Form(new CompoundModel(new Person))l
> form.add(new TextField("couldntbename",new
> ComponentPropertyModel("name")))
>
> so thats almost as much as:
>
>
> Model model = new Model(new Person);
> Form form = new Form(model);
> form.add(new TextField("couldntbename",new PropertyModel("name",model)))
>
> and it is more or less tries to replace the BoundCompoundPropertyModel:
>
>
> BoundCompoundPropertyModel model = new BoundCompoundPropertyModel(new
> Person);
> Form form = new Form(model);
> form.add(model.bind(new TextField("couldntbename"),"name"));
>
> So we better tweak BoundCompoundPropertyModel:
>
> BoundCompoundPropertyModel model = new BoundCompoundPropertyModel(new
> Person);
> Form form = new Form(model);
> form.add(new TextField("couldntbename",model.bind("name")));
>
> so add (or change) the bind method that it just gets a string property and
> returns the model (which is a wrapper around the component and the property
> name)
>
> thats much neater
>
>
> johan
>

Reply via email to