<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.3.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>Laszlonia</title>
	<link>http://laszlonia.com</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Thu, 14 Feb 2008 18:50:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.2</generator>
	<language>en</language>
			<item>
		<title>Convert or Suffer Endless Torment (aka why &#8216;Number()&#8217; helps)</title>
		<link>http://laszlonia.com/?p=5</link>
		<comments>http://laszlonia.com/?p=5#comments</comments>
		<pubDate>Thu, 14 Feb 2008 18:47:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Laszlo - The Dumb Blonde]]></category>

		<guid isPermaLink="false">http://laszlonia.com/?p=5</guid>
		<description><![CDATA[For more information on OpenLaszlo's quirky ECMAScript implementation, <a href="http://www.openlaszlo.org/lps/docs/guide/ecmascript-and-lzx.html">consult the OL Docs</a>.]]></description>
			<content:encoded><![CDATA[<p>As you likely know, OpenLaszlo&#8217;s scripting language is based on Javascript - aka ECMAScript 3.  Now, Javascript is a weakly dynamically typed language (<a href="http://split-s.blogspot.com/2005/02/strongweak-vs-staticdynamic-typing.html">debatable</a>) and has a habit of generating surprising results.  Regardless of whether these &#8216;gotchas&#8217; are a result of the weak dynamic typing or simply Javascript being Javascript, the consequence is that OpenLaszlo scripting is often a bit quirky.</p>
<p>One quirk I just hit had to do with an animator producing funky results when used in conjunction with a data set.  I was simply using the data set to initialize a view to a specified width.  The problem was that when I specified the width directly (e.g. &#8216;150&#8242;), things worked as expected.  However, when I substituted in the data path reference, all I got was junk.  See for yourself:</p>
<h3>Hard Coded</h3>

<div class="wp_syntax"><div class="code"><pre class="text">width changed to
150.150996008178
width changed to
150.691763283001
width changed to
151.617937604377
width changed to
154.079897270667
width changed to
161.488770028828
width changed to
179.951211667618
width changed to
207.510261932941
width changed to
235.523454865409
width changed to
275.229479425737
width changed to
290.190074409226
width changed to
295.099595336075
width changed to
298.583023698865
width changed to
299.67686271424
width changed to
300</pre></div></div>

<h3>Data Set</h3>

<div class="wp_syntax"><div class="code"><pre class="text">width changed to
1500.274198962414936
width changed to
1500.2741989624149362.41547011242939
width changed to
1500.2741989624149362.415470112429394.77836342318196
width changed to
1500.2741989624149362.415470112429394.7783634231819614.2608297578881
width changed to
1500.2741989624149362.415470112429394.7783634231819614.260829757888135.7813996770265
width changed to
1500.2741989624149362.415470112429394.7783634231819614.260829757888135.781399677026545.4549816439118
width changed to
1500.2741989624149362.415470112429394.7783634231819614.260829757888135.781399677026545.454981643911826.9345067269413
width changed to
1500.2741989624149362.415470112429394.7783634231819614.260829757888135.781399677026545.454981643911826.934506726941313.4332687238966
width changed to
1500.2741989624149362.415470112429394.7783634231819614.260829757888135.781399677026545.454981643911826.934506726941313.43326872389665.31212008192
width changed to
1500.2741989624149362.415470112429394.7783634231819614.260829757888135.781399677026545.454981643911826.934506726941313.43326872389665.312120081921.19871422190803
width changed to
1500.2741989624149362.415470112429394.7783634231819614.260829757888135.781399677026545.454981643911826.934506726941313.43326872389665.312120081921.198714221908030.156146668481369
width changed to
150150</pre></div></div>

<p>It seemed odd that in the case of the data set usage, the animator continued to append new values onto the end of the string.  Furthermore, these values seemed to be generally in-line with what the animator should be doing - animating the <code>width</code> up to twice its original value.  Then it hit me - Javascript thought that the value in my <code>width</code> attribute was a string, and it did its best to &#8216;animate&#8217; this string.  The value &#8216;150&#8242; was converted to an number automatically by the animator to perform the animation, and at each iterative step in the animation, the current delta was added on to the original value.  However, although the delta was a number, the original value was a string.  So, OpenLaszlo ended up concatenating the delta value on to the end of the existing original value, resulting in one nasty looking kindof correctish looking string.  Now, that&#8217;s obviously not going to work, is it?</p>
<h3>The Solution</h3>
<p>Make sure you always convert (and validate) data from a data set before you use it.  In my case, all I had to do was to add a call to <code>Number()</code> around my <code>datapath.xPathQuery()</code>:</p>
<h4>No Bueno</h4>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;handler</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ondata&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 awesomeView.setWidth(datapath.xpathQuery(&quot;@awesome_width&quot;));
 coolView.setWidth(datapath.xpathQuery(&quot;@cool_width&quot;));
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/handler<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<h4>Mucho Mejor</h4>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;handler</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ondata&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 awesomeView.setWidth(Number(datapath.xpathQuery(&quot;@awesome_width&quot;)));
 coolView.setWidth(Number(datapath.xpathQuery(&quot;@cool_width&quot;)));
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/handler<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://laszlonia.com/?feed=rss2&amp;p=5</wfw:commentRss>
		</item>
		<item>
		<title>__LZgetNodes: p is null in Datapath</title>
		<link>http://laszlonia.com/?p=4</link>
		<comments>http://laszlonia.com/?p=4#comments</comments>
		<pubDate>Thu, 14 Feb 2008 05:18:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
		
		<category><![CDATA[Laszlo - The Dumb Blonde]]></category>

		<guid isPermaLink="false">http://laszlonia.com/?p=4</guid>
		<description><![CDATA[While slaving away on a recent data-intensive Laszlo project, I happened across the following error:

INFO: __LZgetNodes: p is null in Datapath for container  name: c  id: c

Great - another cryptic error message.  I&#8217;ll spare you the link by link Googlechase and code archealogy that ensued and do what you wish your linear [...]]]></description>
			<content:encoded><![CDATA[<p>While slaving away on a recent data-intensive Laszlo project, I happened across the following error:</p>

<div class="wp_syntax"><div class="code"><pre class="text">INFO: __LZgetNodes: p is null in Datapath for container  name: c  id: c</pre></div></div>

<p>Great - another cryptic error message.  I&#8217;ll spare you the link by link Googlechase and code archealogy that ensued and do what you wish your linear algebra tutor would do: just tell you the right answer.<br />
It turns out that the problem was in the following event handler:</p>

<div class="wp_syntax"><div class="code"><pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;handler</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;ondata&quot;</span><span style="font-weight: bold; color: black;">&gt;</span></span>
 util.setAttributeIfDefined(this, &quot;height&quot;, Number(datapath.xpathQuery(&quot;project/@video_height&quot;))); 
 util.setAttributeIfDefined(this, &quot;width&quot;, Number(datapath.xpathQuery(&quot;project/@video_width&quot;))); 
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/handler<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre></div></div>

<p>As I discovered, I was attempting to access a datapath that had yet to be linked to a data set.  Note to Laszlo Systems: Could we get a bit of contextual help here?  Like we&#8217;re spoiled with when we access a non-existent attribute?  You know, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="text">hello.lzx:2:20: attribute &quot;size&quot; not allowed at this point; ignored 
hello.lzx:2:20: found an unknown attribute named &quot;size&quot; on element &quot;text&quot;, however there is an attribute named &quot;fontsize&quot; on class &quot;text&quot;, did you mean to use that?</pre></div></div>

<h3>The Solution</h3>
<p>Make sure you&#8217;ve actually got a data set associated with the datapath before you use the datapath.  The easiest way to do this is to <strong>use an <code>ondata</code> event handler</strong> instead of <code>oninit</code>, <code>onload</code>, or any of their non-data aware brethren.</p>
]]></content:encoded>
			<wfw:commentRss>http://laszlonia.com/?feed=rss2&amp;p=4</wfw:commentRss>
		</item>
	</channel>
</rss>
