[Laszlo-user] Strange data-binding behavior
André Bargull
a.bargull at intensis.de
Mon Jul 16 08:58:29 PDT 2007
Hello Yang,
this isn't about databinding, it's more about states and constraints,
see "http://www.openlaszlo.org/jira/browse/LPP-631".
Here is just another testcase which shows this misbehaviour and probably
a workaround for you..."LzDelegate#disable()":
[code]
<canvas debug="true" >
<class name="resizeview" width="100" height="80"
onmousedown="this.resizer.apply()"
onmouseup="this.resizer.remove()" >
<resizestate name="resizer" apply="false" >
<attribute name="height" value="$once{this.height}" />
</resizestate>
</class>
<class name="testview" width="300" height="220" bgcolor="0xEAEAEA" >
<attribute name="width" value="${this.redview.width+150}" />
<simplelayout axis="y" spacing="20" />
<resizeview name="redview" bgcolor="red" />
</class>
<simplelayout axis="y" spacing="50" />
<testview name="tv1" >
<state apply="true" >
<attribute name="width" value="${this.blueview.width+150}" />
<resizeview name="blueview" bgcolor="blue" />
</state>
<text options="ignorelayout" text="Both resizeviews will affect
width" align="left" valign="bottom" />
</testview>
<button y="230" options="ignorelayout" text="Disable" >
<handler name="onclick" >
tv1.__LZdelegates[0].disable();
</handler>
</button>
<button y="230" x="80" options="ignorelayout" text="Enable" >
<handler name="onclick" >
tv1.__LZdelegates[0].enable();
</handler>
</button>
<testview name="tv2" >
<attribute name="width" value="${this.blueview.width+150}" />
<resizeview name="blueview" bgcolor="blue" />
<text options="ignorelayout" text="Only the blue resizeview will
affect width" align="left" valign="bottom" />
</testview>
</canvas>
[/code]
Cheers,
André
Yang wrote:
> In the following, there is a lone button whose width is initially
> unset, and then is bound by applying a state. (This is the same as how
> the grid's header buttons works.) The width of the button should never
> change.
>
> However, if we update the data referenced by the button's datapath,
> the button will actually resize.
>
> <canvas>
> <dataset name="d">hello world</dataset>
> <view width="100" name="v">
> <attribute name="doapply" type="boolean" value="$immediately{false}"/>
> <button name="b" datapath="d:/text()">
> <state apply="${parent.parent.doapply}">
> <attribute name="width" value="${parent.width}"/>
> </state>
> </button>
> </view>
> <handler name="oninit">
> LzTimer.addTimer( new LzDelegate( this, 'changeApply' ), 500 );
> LzTimer.addTimer( new LzDelegate( this, 'changeData' ), 1000 );
> </handler>
> <method name="changeApply">
> v.setAttribute('doapply', true);
> </method>
> <method name="changeData">
> d.getPointer().setNodeText('bye');
> </method>
> </canvas>
>
> Is this a bug? This was the smallest test case I could come up with.
>
> If you just set the state's apply to true, the button never even
> expands to width 100.
>
> Furthermore, if you try to add an onwidth handler (such as the
> following) to the button in an attempt to correct the width if it ever
> gets set to something wrong, the setWidth() seems to just be ignored:
>
> <handler name="onwidth">
> if (this.width != parent.width) {
> this.setWidth(parent.width);
> }
> </handler>
>
> The only way I could work around this was to use add another
> timer/delegate/method (with timeout 1).
>
> BTW, is there any way to pass an anonymous block of code to a timer
> (instead of creating and naming a method)? And is there any way to
> pass arguments through a delegate (aside from the
> eventSender/eventName)?
>
> Thanks,
>
> Yang
--
Mit freundlichen Grüßen,
André Bargull
Intensis GmbH
Tel.: +49 (0)231 5522-900
Fax.: +49 (0)231 5522-901
E-Mail: a.bargull at intensis.de
________________________________
Intensis GmbH
Ruhrallee 9
44139 Dortmund
More information about the Laszlo-user
mailing list