[dojo-contributors] Widget property parsing

Alex Russell alex at dojotoolkit.org
Tue Jun 27 17:42:36 EDT 2006

Hi Neil,

One quick note: it would be good if your email messages contained your 
full name somewhere, as we now have two Neil's who are heavily involved 
in the project.

On Monday 26 June 2006 5:56 pm, Neil wrote:
> In the process of patching the dojo toolkit for some bugs I have come
> across a problem with the widget package.  There currently does not
> exist a way to map attributes from a given tag that do not follow the
> convention, name-value pair.

Assuming that I understand you correctly (which I'm not certain of), I 
don't think you're correct in this assertion. Arrays and map-style 
objects are handled by the mixInProperties() method. Arrays are 
replaced with new array objects which contain strings split on the ";" 
chrachter from the node attribute. If your widget contained:

	this.foo = ["bar", "baz"];

You could repalce it in the markup with:

	<div dojoType="blah" foo="thud;xyzzy">...</div>

Objects are likewise mapped back from attribute values:

	this.foo = {bar: "blah blah", baz: "blabber"};

could be created with:

	<div dojoType="blah" foo="bar:blah blah;baz:blabber">...</div>

> Some attributes within desired 
> supported tags only contain a name value where it is assumed that the
> value implies an affirmative action.

Properties set on nodes that do not match an initially populated 
property of a widget object are available as raw string values in the 
extraArgs map which is a property of every widget object.

You can retreive a custom property in a widget's fillInTemplate method 
like this:

	fillInTemplate: function(args, frag, parent){
		// you can cast it to something other than a string here
		this.someCustomProperty = this.extraArgs["somecustomproperty"];
		// ...

With all of that said, I'm still not sure that I understand your 
original concern adequately to know if this is a reasonable solution to 
the problem you're trying to describe.


> This mapping of attributes to 
> properites within an object occurs when parsing the tree and building
> the widget.  Currently I have worked around the lacking of mapping of
> some tag attributes to objects by using directly the "frag" object to
> determine the correct behavior of the widget. I believe there should
> be a more elegant and generic means by which the attributes missed by
> the mapping should be conducted in the future.  Any suggestions?

Alex Russell
alex at dojotoolkit.org BE03 E88D EABB 2116 CC49 8259 CF78 E242 59C3 9723
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 188 bytes
Desc: not available
Url : http://mail.dojotoolkit.org/pipermail/dojo-contributors/attachments/20060627/b3581749/attachment.sig 

More information about the dojo-contributors mailing list