Re: Nested component communication
Re: Nested component communication
- Subject: Re: Nested component communication
- From: Zak Burke <email@hidden>
- Date: Wed, 11 Aug 2004 14:58:06 -0400
David,
I confess I haven't investigated the subtleties of WOComponent parameter
passing.
Using the same technique I mentioned origianlly, I have built deeply
nested structures where, for example, the items contained in a
WORepetition are themselves components.
The component will have code like this:
<WEBOBJECT NAME=foRepetition>
<WEBOBJECT NAME=foItemTemplate></WEBOBJECT>
</WEBOBJECT>
====
foRepetition: WORepetition {
item = foItem;
list = foList;
}
foItemTemplate: ItemSummary {
fo = foItem;
}
And the subcomponent will have an instance variable named "fo".
This is essentially the reverse of what I initially described: instead
of a component passing a value up to a wrapper, this is a component
passing a value down to a sub-component. If that's what you're trying to
do, then I'm really stumped, because the technique works for me.
To debug the problem, try stashing NSLog.out.println statements in the
WO magic methods (the constructor, awake, appendToResponse) to see if
the object is being set and overwritten or if it's never being set.
As to whether the nested component's variables are public or private, it
shouldn't technically matter, although private variables with get/set
methods are superior from an OO point of view, and WO will find "setKey"
and "getKey" automatically when you try to set "key" from a separate
component or from a web form.
zak.
David Holt wrote on 8/11/04 12:25 PM:
Thanks Zak,
Your response makes me think that I should clarify my problem a little
better.
Variables pass from the component content to the Wrapper component
perfectly. I am using a pageTitle dynamically generated from the
componentContent binding.
My problem seems to be how to pass the variable from the
componentContent to its nested navigation bar and from the navigation
bar to its nested menu elements. Should I be using setter methods
explicitly? I think that the variable value is passing, but then is it
possible it is getting reset during the response loop? There is an
example in the old WebObjects Developer's Guide for version WO4.5 that
shows a parent component synchronizing to a child, and a child
synchronizing to the parent. The book says (on page 148): "For instance,
it's sufficient in the example shown in Figure 35 to simply declare a
childValue instance variable in the child component and a parentValue
instance variable in the parent." on the following page it says:
"Component synchronization can sometimes lead to values being set when
you don't want time to be set. You have no control over when, or how
often a value is passed to and from the parent."
Is there a better way for a nested element to know where it is (i.e.
which page level component is displaying it) and base its behaviour on
where it is?
On 11 Aug 2004, at 5:44 AM, Zak Burke wrote:
David,
Yeah, I've had a hard time tracking down details about inter-component
communication. Here's what works for me: In the api file of the
component which is being wrapped, you can directly set the wrapper's
variables like this:
WebObjectTagName: WrapperComponent {
var1 = "static string value";
var2 = aMethodValue;
}
This assumes that:
* the class WrapperComponent has variables var1 and var2. set-methods
probably work too, but I haven't tried
* the inner component's class has a method aMethodValue()
* var2 and the value returned by aMethodValue() are the same type
In your case, it sounds like you should be able to set the wrapper
class's "tabOne" variable from the wrapped pages, just like setting
var1 in the example above.
Good luck --
zak.
David Holt wrote on 8/10/04 6:52 PM:
Hello,
I am trying to get a navigation bar to work so that an image changes
when the user is on the page (like the tabs on Apple's site).
The way I have set it up is to have a page wrapper containing a
WOComponentContent and a NavigationBar Component made up of Rollover
components. In my API for the wrapper I have set a boolean variable
called "tabOne" and for all of the components that fill the
"WOComponentContent" under "tabOne" I have set their "tabOne" binding
to "true".
I have also placed "tabOne" variables in the wrapper component, the
NavigationBar component and the Rollover component. I have wrapped
the rollover button for tabOne in a conditional to display the
rollover when the boolean is false (i.e. not on a page that is in
tabOne) and a static image when the boolean is true. My problem is
that the boolean is always evaluating to false on pages where
"tabOne" is true and as a result only the rollover is displayed in
its conditional. From my reading, it seems that the component
communication is automatic from the parent components to child
components so long as the variables are named the same thing.
Am I misunderstanding something about how the communication would
occur from ComponentContent>Wrapper>NavigationBar>Rollover ? If so,
what would be a better way to implement this? Thanks,
David
_______________________________________________
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.
_______________________________________________
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.