View Full Version : datapointer's ondata in 2.1
cmcginnis
05-19-2004, 01:34 PM
In previous versions of LPS (1.*) the datapointer would call its "ondata" for ever doRequest() call. In 2.1.2 it seems that it only executes its ondata the first time doRequest() is called. Is there anyway to force it to send an ondata (or someother event) every time there is a doRequest() and information is present?
vfunshteyn
05-19-2004, 01:56 PM
I think you may want to declare your datapointer with rerunxpath="true".
antun
05-19-2004, 02:06 PM
I think you want to use <dataset>'s ondata event for that instead of <datapointer>'s. The former should be sent wenever the response comes in, whereas the latter will only get sent if the data changes.
-Antun
cmcginnis
05-19-2004, 02:36 PM
I actually never see the ondata of the dataset ever being executed. Here is the test code:
<canvas debug="true" width="800" height="600">
<dataset name="refineTool" autorequest="false" ondata="Debug.write('refineTool dataset ondata')"/>
<view name="getColors" id="getColors">
<button name="colors1" onclick="getColors.getColorData('360D-6')">One</button>
<button name="colors2" onclick="getColors.getColorData('370D-6')">Two</button>
<simplelayout axis="x" spacing="10"/>
<datapointer name="refineToolPtr" xpath="refineTool:/*"/>
<method name="getColorData" args="colorCode"><![CDATA[
refineTool.setSrc("controllers/getRelatedColors.jsp");
var query = "startColor=" + colorCode + "¤tColor=" + colorCode + "newSegment=15&action=start";
refineTool.setQueryString( query );
refineTool.doRequest();
]]></method>
</view>
</canvas>
When I move the ondata to the datapointer I do see it write out.
antun
05-19-2004, 03:09 PM
You're missing type="http" in the <dataset> tag.
The LPS won't know it's an HTTP dataset if you set the src dynamically. If you give it a src starting with "http:" in the tag, then type="http" is implied.
Also:
setSrc( "http:controllers/getRelatedColors.jsp" )
... might work.
-Antun
cmcginnis
05-19-2004, 04:26 PM
Actually it seems as if the datapointer is not being reset between doRequest() calls. It will work the first time, but fail the next. For example:
<canvas debug="true" width="800" height="600">
<dataset name="refineTool" type="http" autorequest="false" />
<view name="getColors" id="getColors">
<button name="colors1" onclick="getColors.getColorData('360D-6')">One</button>
<button name="colors2" onclick="getColors.getColorData('370D-6')">Two</button>
<simplelayout axis="x" spacing="10"/>
<datapointer name="refineToolPtr" xpath="refineTool:/*" ondata="getColors.printData()"/>
<method name="getColorData" args="colorCode"><![CDATA[
refineTool.setSrc("controllers/getRelatedColors.jsp");
var query = "startColor=" + colorCode + "¤tColor=" + colorCode + "newSegment=15&action=start";
refineTool.setQueryString( query );
refineTool.doRequest();
]]></method>
<method name="printData">
Debug.write(refineToolPtr.serialize());
refineToolPtr.selectChild();
Debug.write(refineToolPtr.getNodeAttribute("colorName"));
</method>
</view>
</canvas>
The first time I get the serialize and the color name from the Debug in the "printData" method. The second time gets nothing.
I have noticed that if I use the dupePointer() method and get a copy of the datapointer I can use that throughout the printData method multiple times like so:
<method name="printData">
var dupe = refineToolPtr.dupePointer();
Debug.write(dupe.serialize());
dupe.selectChild();
Debug.write(dupe.getNodeAttribute("colorName"));
</method>
I also imagine that I could just do xpathQuery() on the original datapointer, and it would work also, but I haven't tried it yet.
So is this expected behavior, or should we not be using selectChild(), selectNext() and so on in our application.
Thanks
vfunshteyn
05-19-2004, 05:09 PM
The problem with ondata not firing the second time on the datapointer seems strange; I modified your example to use a sample HTTP dataset, and ondata is sent every time either button is clicked. One possibility is that the backend returns an error, which you could verify by adding an onerror handler to the datapointer/dataset or reconstructing the URL in the browser.
cmcginnis
05-19-2004, 05:12 PM
When it was not working, I was not calling dupePointer() and had a selectChild() call in the method that was called by the ondata event.
When I use the dupePointer() method it works perfect every time.
antun
05-19-2004, 11:10 PM
The selectChild method will move the datapointer to a new node. Could it be that this is why the second time it was not firing?
-Antun
Originally posted by cmcginnis
When it was not working, I was not calling dupePointer() and had a selectChild() call in the method that was called by the ondata event.
cmcginnis
05-20-2004, 09:15 AM
Using the previous version of LPS (beta-1.0.3) everytime the a doRequest() was called the ondata event would be fired and the datapointer would be set to the first most root element.
With LPS 2, after performing a selectChild() or selectNext() the ondata event doesn't even fire, let alone reset the pointer back to the root element. The dupePointer works because we never actually move the datapointer - it just remains at the root element. It's the copies of the datapointer that we are now moving around.
In the "Porting your application from LPS v.1" document it does say that you need to adjust the xpath for a datapointer to point at the first child of the root, but says nothing about having to reset the pointer or not calling select methods.
I'm just wondering if this is a bug, or if I am misunderstanding something and doing it incorrectly, becuase making a copy of the datapointer everytime I want to use it seems a little ugly. Perhaps just using the xpathQuery() method to get the values from the dataset would be cleaner.
Anyway, just want to make sure that I am coding this properly so it doesn't come back to bite me later on.
antun
05-20-2004, 10:24 AM
Using the previous version of LPS (beta-1.0.3) everytime the a doRequest() was called the ondata event would be fired and the datapointer would be set to the first most root element.
In 1.0.x, the datapointer would not be reset to the first root element when a request came back from the server. It shouldn't be reset in 2.1.2 either. If you either declare the datapointer with an xpath or move the pointer using its APIs (e.g. setXPath(), selectChild(), etc., it should stay where you put it.
In the "Porting your application from LPS v.1" document it does say that you need to adjust the xpath for a datapointer to point at the first child of the root...
That's referring to the use of datapointers to signal a response from the server (your original question). Like I said, you can use dataset's ondata method for this instead - that's exactly what it's for.
-Antun
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.