[Laszlo-user] attribute setters

P T Withington ptw at pobox.com
Tue Oct 21 18:42:53 PDT 2008


Setters will, as you suspect, be called as the instance is being  
constructed when the initial values of the attributes are installed.   
If the setter is complex, it will need to guard against trying to  
operate on an incomplete instance.  In this case, the programmer is  
probably trying to guard against accessing the 'field' child node too  
soon.  (Setters are invoked before children are created, because you  
don't want the children to be trying to access an incomplete parent.)

An alternative approach, which would be safe would be to use a  
constraint to constrain 'field's maxlength to be the same as the parent.

     <_internalinputtext name="field" maxlength="${parent.maxlength}

I can't say why the original designer did not use this approach, as  
several other parameters of 'field' are handled this way.  Perhaps  
there is a subtle timing issue beyond just the init sequence that is  
being addressed.

I'm afraid I can't endorse looking at the components sources as a good  
model of LZX style, simply because many of them are extremely  
complex.  But the mailing lists are a great place to ask this kind of  
question so the knowledge can be shared with the general community.

You have indeed spotted a bug.  Please report it to http://jira.openlaszlo.org 
.

On 2008-10-21, at 18:03EDT, Greg Denton wrote:

> I upgraded to 4.2b2 and am trying to figure out and work my way
> through all the 'setFoo deprecated' warnings. Here's a good ref:
> http://wiki.openlaszlo.org/Runtime_Differences#Attribute_setters_defined_with_.3Csetter.2F.3E
>
> One of the first library files I looked at to get examples was
> edittext and came across this for maxlength:
>
>        <attribute name="maxlength" value="null" type="number"/>
>        ....
>        <method name="init">
>            ...
>            field.setAttribute('maxlength', this.maxlength);
>            field.setAttribute('pattern', this.pattern);
>
>            ]]>
>        </method>
>        ...
>        <method name="setMaxlength" args="n">
>          this.setAttribute('maxlength', n);
>          this.field.setAttribute('maxlength', n);
>        </method>
>
> Seems like the "setter" tag was not used just to avoid setting the
> field attribute before init. But isn't this a bug since field's
> maxlength will not be set when edittext.setAttribute('maxlength', 20)
> is called? Or, is this a common pattern for setters?
>
> Thanks.



More information about the Laszlo-user mailing list