PDA

View Full Version : Auto refresh dataset


clillo
09-22-2005, 10:30 AM
I'm looking for assistance to efficiently and automagically refresh a dataset content to a grid component every 60 seconds. A simple sample will be appreciated.

thanks

Cesar

shankara
09-23-2005, 06:14 AM
Even i would appreciate if someone tells how to auto refresh the data from a dataset.

whenever i add any data to a dataset i need to refresh the browser to access the newly added data.Is there any way using which we can dynamically display the data along with adding it to the dataset.

Micheal722
09-26-2005, 07:08 AM
you can make a init function for canvas,it contain a time component like this:
<canvas oninit="initUI()">
<dataset name="elementData" request="false" type="http" src=""/>

<method name="initUI">
<!--set a path to dataset-->
elementData.setAttribute("datapath","Lawyer/elementConfig.xml");
elementData.doRequest();
<!--point other approach that name is "fadeText"-->
this.fadeDelegate = new LzDelegate(this, "fadeText" );
<!--after 3 seconds-->
LzTimer.addTimer( this.fadeDelegate,3000);
</method>

<method name="fadeText">
<!--reset the same path to dataset-->
elementData.setAttribute("datapath","Lawyer/elementConfig.xml");
elementData.doRequest();
<!--redo executing "initUI" after 3 seconds-->
this.fadeDelegate = new LzDelegate( this, "initUI" );
LzTimer.addTimer( this.fadeDelegate,3000);
</method>

</canvas>

clillo
09-26-2005, 09:44 PM
This refresh worked for me..hope it will for U.

<dataset name="syslog" src="http://hostname/xml/syslog.php"
request="true" type="http"
timeout="90000"
ondata="Debug.write( 'Syslog data came back' );refresh()"
onerror="Debug.write( 'Syslog data error' )"
ontimeout="Debug.write( 'Syslog data timeout' )" />

<method name="refresh">
this.refreshDelegate = new LzDelegate( this, "refreshData" );
LzTimer.addTimer( this.refreshDelegate, 30000 );
</method>

<method name="refreshData">
Debug.write( "== AutoRefreshing Syslog window =======" );
syslog.doRequest();
</method>

**** also added a button to manually refresh the data ****
<button placement="title_area" height="16" >Refresh
<method event="onclick">
Debug.write( "== Refresh Button Syslog =======" );
syslog.doRequest()
</method>
</button>

shankara
09-27-2005, 02:28 AM
Thank you for the reply.
I am still not able to auto refresh the dataset.Debugger is showing an error message
"Undefined reference to function refresh"
but the refresh button works fine though.I tried to troubleshoot it but in vain can you look at it once?

Micheal722
09-29-2005, 02:20 AM
if the button has worked fine,you can try to put the code into the time component.

shankara
09-29-2005, 02:36 AM
with the above code to me it still gives errror in the debugger "undefined refrence to function refresh" Until a while ago it didn't work,but when i added "canvas.refresh()" to ondata event voila!!! it Worked!!! here is the code:

<dataset name="data" src="http://localhost:8080/lps-3.0.2/sample4-xmllogin/src/contacts.xml" request="true"
type="http" timeout="90000" ondata="Debug.write('Auto refresh');canvas.refresh()" onerror="Debug.write('Error')" ontimeout="Debug.write('Timeout')"/>

<method name="refresh">
this.refreshDelegate = new LzDelegate(this,"refreshData");
LzTimer.addTimer(this.refreshDelegate,5000);
</method>

<method name="refreshData">
Debug.write("Refresh Working");
data.doRequest();
</method>

<button text="Refresh" x="100" y="10">
<method event="onclick">
Debug.write("Data Refreshed");
data.doRequest();
</method>
</button>

can you please tell me WHY it worked after adding "canvas.refresh()" instead of refresh and why did it give me an error message earlier.I have no clue.

Thank you everyone for all the help
shankara

mojoTivo
10-12-2005, 06:29 AM
I had a problem with the final example. It worked fine for auto-refreshing, but when I used my "Update Now" button, it would launch another timer and ultimately my refreshes would start happening more and more frequently. So, I combined code from the previous posts (Thanks!) to create a version that works for both "Auto" and "Button". At least, it works for me:


<canvas debug="true" oninit="initTimers()">

<method name="initTimers">
this.refreshDelegate = new LzDelegate(this,"refreshData");
</method>

<method name="refresh">
LzTimer.resetTimer(canvas.refreshDelegate,15000);
</method>

<method name="refreshData">
Debug.write("Refresh Working");
Route.doRequest();
</method>

<dataset name="Route"
request="true"
type="http"
src="http://www.website.com/routerlist.php"
ondata="Debug.write('Auto refresh');canvas.refresh()"
/>

<simplelayout axis="y"/>
<button onclick="Route.doRequest()">
Update Now
</button>
<view datapath="Route:/routerdata/router">
<simplelayout axis="x"/>
<text datapath="name/text()"/>
<text datapath="ip/text()"/>
<text datapath="location/text()"/>
<text datapath="time/text()"/>
</view>
</canvas>


I hope this helps someone. Thanks to everyone for the pointers.