Re: So what is a good approach to learning WebObjects?
Re: So what is a good approach to learning WebObjects?
- Subject: Re: So what is a good approach to learning WebObjects?
- From: David LeBer <email@hidden>
- Date: Sun, 16 Nov 2003 10:28:54 -0500
On 16-Nov-03, at 9:31 AM, Drew Thoeni wrote:
On Nov 16, 2003, at 12:34 AM, Arturo Pirez wrote:
My background looks like this: lots of web development but using
scripting
languages, so my thinking is still fairly procedural.
A procedural mentality is very very bad for this sort of thing.
Here's the
trick. When you use WO to create a popup list do you spend time
trying to figure out how to convert the selected string into
something else?
Here's a contrived example. I have a bunch of pets with associated
owners.
I create a popup list to display the pets' names. When a pet's name
is selected and
I hit submit I want to display the owner's address. How would you go
about
doing that?
Arturo,
I too am new to WebObjects and suffer pretty much the same background
as Alice. I think I understand your comment, above, but it would be
helpful if you could clarify by providing the "answer". I know how I'd
go about it in a procedural language. But, not being sure about the OO
answer, I'm not sure my guess would get me any further along.
How would you suggest it be done?
Drew
Well that example truly does seem contrived to me : )
If it will help I will outline one way I might deal with this.
Assuming: That all objects are EO's and a Pet object has an attribute
named petName, and a relationship called 'owner' to their Owner and
that an Owner object has a relationship called 'address' to an Address
object .
We start with an NSArray of Pet objects that I bind to the 'list'
binding of the WOPopupButton. I give it a place holder Pet object which
I bind to the 'item' binding, I'll name it 'petItem'. I need to know
what object was selected so I will provide another Pet object called
'selectedPet' that I will bind to the WOPopupButton 'selection'
binding. We are going to display the pets name in the popup to identify
each Pet object instance so I will bind the 'displayString' of the
WOPopupButton to 'petItem.petName'.
See
<http://developer.apple.com/documentation/WebObjects/Reference/
DynamicElements/WOPopUpButton/index.html> for more details on
WOPopupButton
When the form is submitted, the Pet object associated with the selected
petName will be placed into the selectedPet object.
From selectedPet I can now navigate through the object relationships to
the appropriate Address. Like this:
'selectedPet.owner.address' giving me an Address object of that pet's
owner. So we might have an action in bound to our submit button that
looks like this:
//Assuming we have an Address object with accessors
//Using key value coding
public WOComponent assignAddress() {
if (selectedPet != null) {
setAddress((Address)selectedPet.valueForKeyPath("owner.address"));
}
return null;
}
OR
//Using method calls (will break if owner returns null)
public WOComponent assignAddress() {
if (selectedPet != null) {
setAddress(selectedPet.owner().address());
}
return null;
}
HTH
;david
--
David LeBer
Codebase Software Systems
_______________________________________________
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.