Re: Binding WOString to method with parameters
Re: Binding WOString to method with parameters
- Subject: Re: Binding WOString to method with parameters
- From: Arturo PĂ©rez <email@hidden>
- Date: Fri, 26 Mar 2004 08:20:09 -0500
On Mar 25, 2004, at 11:33 PM, Randall Cayford wrote:
I'm new to webobjects so this may turn out to be a case of completely
misusing the tool but I'm baffled.
Sometimes it's a baffling tool. Fortunately, in this case it's not.
Sometimes a live demo helps where the documentation fails. You might
want to see if you can get copies of the WWDC WebObjects movies.
I have a table with 5 cells. In each of these cells I would like to
put a WOString which displays a number from one of my java classes. I
could define a set of 5 functions and bind each WOString to a
different function but that just seems wrong to me.
This is one of those areas where WO really shines.
So I would like to bind the WOString to a function which takes an
argument. So I would have something in my page class like:
int getSpeed(int lane) {
return(speed[lane]);
}
No, no parameters to bindings. But there is a (IMO) better way.
which returns the correct value for each cell depending on the value
of lane.
If I can bind to a function with arguments, where and how do I get the
arguments set and passed to the function?
But then how do I wrap the WOString in something which allows me to
set the currentLane variable for the particular cell?
This is the core of the possibly better way. You use a WORepetition to
iterate through your values. Say you have an array of Lane objects
defined as
class Lane {
public int speed;
public String color;
public Object swimmer; // a picture of the swimmer using the lane :-)
}
You bind the list of WORepetition to laneArray and the item to
laneItem. Then you can bind your WOString to your method getSpeed()
which looks like
public String getSpeed() {
return laneItem.speed;
}
The WORepetition guarantees (barring mistakes like I recently made :-)
that laneItem is set to the proper value when referred to as above.
It's a very neat and powerful feature of WO.
You can bind the count of the repetition instead of the item but I've
not found that as generally useful.
----
WO in philadelphia - wanna cheesesteak with that?
Please visit webobjects.meetup.com.
_______________________________________________
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.