Re: Pass-through bindings from parent to child component
Re: Pass-through bindings from parent to child component
- Subject: Re: Pass-through bindings from parent to child component
- From: Chuck Hill <email@hidden>
- Date: Mon, 7 Jan 2008 10:08:37 -0800
Hi Paul,
On Jan 6, 2008, at 10:25 PM, Paul Hoadley wrote:
On 07/01/2008, at 3:27 PM, Chuck Hill wrote:
On 03/01/2008, at 4:18 PM, Paul Hoadley wrote:
Is there an idiom for passing through _any and all_ bindings
from a parent to a child component without being specific about it?
Simply put, no. The is reason is that parents do not pass
bindings to their children. The children take them from their
parents. If the child was not written to handle arbitrary
bindings, there is no way you can force it to. You could subclass
the child and extend it to handle any and all bindings.
OK, there's something important I was missing.
That is, I've got a component that wraps a Dynamic Element. If I
add the binding 'abc="xyz"' to, say, a WOTextField, it will pass
that through to the HTML 'input' element as an attribute and its
value.
It does not pass them through to WOTextField. WOTextField (or one
of its superclasses, WOInput or WOHTMLElement, I don't recall and
am too lazy to figure it out) has code to take any bindings that
it does not recognize and add them to the input as key=value.
OK.
How can I get my containing component to do something similar—is
there an idiom for passing completely arbitrary bindings from a
parent to a child component? If I can work that out, I think I
can answer my original questions:
1. I want to be able to set any bindings on the WOBrowser which
were set on the LSBrowser. I can list them out in the WOD:
browser : WOBrowser {
list = ^list;
item = ^item;
selections = ^selections;
displayString = ^displayString;
multiple = ^multiple;
id = ^id;
value = ^value;
escapeHTML = ^escapeHTML;
selectedValues = ^selectedValues;
name = ^name;
disabled = ^disabled;
size = ^size;
class = classList;
}
But then WOLips flags an error because I've "set"
'selectedValues' and 'selections'. All I'm trying to express
here is that whichever of the two is set on the parent should be
passed through to the child.
I think that what you need to do is to implement LSBrowser as a
WODynamicElement so that you have the necessary access to the
bindings. This means that instead of using a WOBrowser, you are
going to have to re-implement it. Subclassing WOBrowser might be
a good approach.
Maybe I've wandered too far down the wrong path here, so I'll ask a
different question. For now, the only additional functionality I'm
trying to add to the dynamic elements is the classList() method
referred to in the WOD above. (This returns a string containing a
space-separated list of classes which ends up as the value of the
HTML "class" attribute for CSS styling.) So I've created an
LSComponent which extends WOComponent and implements classList().
So currently LSBrowser extends LSComponent. If I have LSBrowser
extend WOBrowser (or WODynamicElement), I'm going to need to
duplicate classList() in LSTextField, LSCheckBox, and so on. Am I
going about this (adding a method to the standard dynamic elements)
the wrong way?
I can't think of a way to add methods to the standard elements
without re-implementing them. But perhaps you are going about
implementing CSS in the wrong way. I must admit that I am not seeing
part of this picture. When I use a WOBrowser, I might have something
like this:
class = "boxOutline requiredField formFont";
I am guessing that you are deriving classList in some other manner.
Not having any idea how you have done that, I would suggest moving
the logic elsewhere. It if is sufficiently static, you could put it
in an NSDictionary in application, keyed on the element name. Then
you could use a binding on WOBrowser like
application.cssClassesFor.WOBrowser;
where cssClassesFor is a public method on Application that returns an
NSDictionary.
Another thing to consider is to override this method on Application:
public WOElement dynamicElementWithName(String aName,
NSDictionary someAssociations,
WOElement anElement,
NSArray aLanguageArray)
and add your class = whatever binding to the someAssociations
dictionary like so:
if ( someAssociations.objectForKey("class") == null) {
NSMutableDictionary associations = someAssociations.mutableClone();
associations.setObjectForKey(new WOKeyValueAssociation
("application.cssClassesFor.WOBrowser"), "class");
}
That way, you can override the classes on the element, but it you do
not specify the class then you get the default.
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden