Re: Binding method called thrice
Re: Binding method called thrice
- Subject: Re: Binding method called thrice
- From: Jonathan Rochkind <email@hidden>
- Date: Mon, 29 Mar 2004 11:14:20 -0600
As you've figured out, WO can "process" your .html/.wod up to three
times in a request-response loop. Once in each of the control points
you've identified---takeValuesFromRequest, invokeAction,
appendToResponse.
This is just the way WO works. By "process", I guess I basically
mean: traverse the tree of elements and components that make up the
page.
If you've got form inputs inside the repetition, WO's got to call the
'list' binding during takeValuesFromRequest to go through the
repetition and assign values to those elements. Even if you don't
have form elements in the repetition, if you've got form elements
elsewhere on the page, WO might call the 'list' binding to traverse
the element tree in order to _discover_ that nothing inside the
repetition needs to have a form input assigned to it.
Likewise, if you've got something bound to an action method inside
the repetition, WO has got to call the 'list' binding during
invokeAction in order to figure out what action method to call, and
make sure the page's state is set correctly when the action method is
called (so you can refer to your 'item' binding in the action method).
And of course, when WO is generating the page during
appendToResponse, WO has got to call the 'list' binding to generate
the proper repeated results for the WORepetition.
Just the way WO works.
If your problem is that you've got side effects in your getUnits
method that you don't want being called three times---get rid of
these side-effects. Put them somewhere else. If you want the side
effects called only when the page is actually generated, put them in
an over-ridden appendToResponse, probably before call to super.
If your problem is that getUnits dynamically calculates an NSArray,
and this calculation is expensive and you don't want to perform it
multiple times--then cache it:
public NSArray getUnits() {
if ( units == null ) {
units = [etc, calcuate it]
}
return units;
}
Now the 'units' is only calculated once, and cached. If you want to
re-calculate it each time the page is generated, then again over-ride
appendToResponse and simply set 'units' to null before calling super.
An over-ridden appendToResponse is a useful place to put any code
that you want to run every time the page is generated, but no more.
--Jonathan
At 12:08 PM +0200 3/29/04, Thomas Drevon wrote:
Hi,
I have a WORepetition in a sub component where the list binding is a
method call. The method looks something like this:
public NSArray getUnits() {
// do stuff on global private NSArray array
return array;
}
Now, the problem is that this method is called not once, but thrice!
Debugging has revealed the following request-response loop:
takeValuesFromRequest before super
getUnits()
takeValuesFromRequest after super
invokeAction before super
getUnits()
invokeAction after super
component appendToResponse before super
sub component appendToResponse before super
getUnits()
sub component appendToResponse after super
component appendToResponse after super
To my understanding, the last call to getUnits() is the only one
that should take place.
I've tried to set synchronizesVariablesWithBindings to return false
on my sub component (and sync bindings to the super component
manually), but it doesn't make any difference.
I've also made sure that my wod file is clean of any (in)visible
objects that might call stuff (anyway, this would have triggered
stuff in appendToResponse, not takeValuesFromRequest and
invokeAction).
Side note: My sub component does not contain a form, but is inside a
form in the super component. However, my sub component includes a
button that submits the form it is placed inside.
Does anyone have suggestions what might cause this? Any help is
appreciated :-)
cheers,
Thomas
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.