Bypassing OGNL

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Bypassing OGNL

Thomas J du Plessis
Hi all
I have a Form to which I pass a CompoundPropertyModel containing an object. I then rely on Wicket's 'magical' ability to map object fields to wicket components.  Like this:

IModel model = new CompoundPropertyModel(myObject);
add(new MyForm("MyForm", model));
......
and then in MyForm:
add(new TextField("total")); // This calls getTotal() in my object through OGNL

This is all brilliant and working beautifully.  However I'd like to be ale to add a wicket component for which the id annot be mapped to an accessor in my model object. Eg:
in MyForm:
add(new TextField("calculatedValue"));  // There is no getCalculatedValue() in myObject

When I try this, I get an OGNL exeption.  So the problem is that I seem to be unable to use 'non-mapped' wicket id's when I'm using CompoundPropertyModel.  Is this true?

Can anyone tell me how I can achieve this?

Much appreciated,
Thomas

Reply | Threaded
Open this post in threaded view
|

Re: Bypassing OGNL

Martijn Dashorst
Administrator
Either use the BoundCompoundPropertyModel, or provide that specific component with a separate PropertyModel.

add(new TextField("calculatedValue", new PropertyModel(foo, "propertyName")));  // There is no getCalculatedValue() in myObject

Martijn

On 1/3/06, Thomas J du Plessis <[hidden email]> wrote:
Hi all
I have a Form to which I pass a CompoundPropertyModel containing an object. I then rely on Wicket's 'magical' ability to map object fields to wicket components.  Like this:

IModel model = new CompoundPropertyModel(myObject);
add(new MyForm("MyForm", model));
......
and then in MyForm:
add(new TextField("total")); // This calls getTotal() in my object through OGNL

This is all brilliant and working beautifully.  However I'd like to be ale to add a wicket component for which the id annot be mapped to an accessor in my model object. Eg:
in MyForm:
add(new TextField("calculatedValue"));  // There is no getCalculatedValue() in myObject

When I try this, I get an OGNL exeption.  So the problem is that I seem to be unable to use 'non-mapped' wicket id's when I'm using CompoundPropertyModel.  Is this true?

Can anyone tell me how I can achieve this?

Much appreciated,
Thomas




--
Living a wicket life...

Martijn Dashorst - http://www.jroller.com/page/dashorst

Wicket 1.1 is out: http://wicket.sourceforge.net/wicket-1.1
Reply | Threaded
Open this post in threaded view
|

Re: Bypassing OGNL

Johan Compagner
In reply to this post by Thomas J du Plessis
see the BoundCompoundPropertyModel
there you can bound a property expression to a textfield.

something like this;

IModel model = new BoundCompoundPropertyModel(myObject
);
add(new MyForm("MyForm", model));
......
and then in MyForm:

TextField tf = new TextField("total") 

add(tf); // This calls getTotal() in my object through OGNL

model.bind(tf,"property")

johan



On 1/3/06, Thomas J du Plessis <[hidden email]> wrote:
Hi all
I have a Form to which I pass a CompoundPropertyModel containing an object. I then rely on Wicket's 'magical' ability to map object fields to wicket components.  Like this:

IModel model = new CompoundPropertyModel(myObject);
add(new MyForm("MyForm", model));
......
and then in MyForm:
add(new TextField("total")); // This calls getTotal() in my object through OGNL

This is all brilliant and working beautifully.  However I'd like to be ale to add a wicket component for which the id annot be mapped to an accessor in my model object. Eg:
in MyForm:
add(new TextField("calculatedValue"));  // There is no getCalculatedValue() in myObject

When I try this, I get an OGNL exeption.  So the problem is that I seem to be unable to use 'non-mapped' wicket id's when I'm using CompoundPropertyModel.  Is this true?

Can anyone tell me how I can achieve this?

Much appreciated,
Thomas