View Full Version : Example code
mohan
09-17-2003, 07:45 AM
Hai Antun,
How do i pass the combo box value via jsp variable over http and also how do i set this variables using the either setQueryString() and setQueryParams().Actually in my application i am quering database using this combo box value to retrieve the data.
Is there any example code on the same.
With regards,
Rudresh.
antun
09-17-2003, 08:29 AM
You define a dataset that will contain the XML response of your jsp:
<dataset name="mydatast" src="myjsp.jsp" autorequest="false" />
Next, like I showed you here:
http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=368
... you obtain the selected value of the combobox somewhere in script, and call the setQueryParams() method of a dataset:
var s = mycombo.getSelectedText();
var ds = canvas.datasets.setQueryParams( {myparam : s} );
ds.doRequest();
... then the request will happen. Since data requests are asynchronous in Laszlo, if you want something to happen when the data comes back, you'll have to set it for the ondata event. Typically you might set up a <datapointer> to point somewhere in the dataset before the request is sent, even if there is no data in the dataset. Then you'd define an ondata method for that pointer, to execute any code. See here on how to do that:
http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=344&highlight=ondata+datapointer#post1194
Alternatively, if you have views bound to the data in mydataset, they will automatically be updated/created when the response comes.
-Antun
mohan
09-18-2003, 07:57 AM
Hi Antun,
I tried this code but no luck.
-------------------------------------------------------
<canvas debug="true">
<dataset name="dset" src="matchtestdb123.jsp" autorequest="false" type="http" />
<class name="image">
<attribute name="imgsize" value="50" type="number" />
<method name="applyData" args="d" >
Debug.write("images: "+d);
if (d == null) { return; }
setSource("http://localhost:8080/lps-v1/lz-utils/mallesh1/images/" +d);
</method>
</class>
<dataset name="namelist" >
<items>
<item>male</item>
<item>female</item>
</items>
</dataset>
<simplelayout />
<combobox x="10" y="50" width="102" shownitems="2"
itemfield="nameList:/items/item/text()"
datapath="nameList:/items/item[1]/text()"
id="mycombo" >
<method name="getSelectedText">
return this.top.subviews[3].getText();
</method>
</combobox>
<view x="150" y="0" resource="images/go.png" clickable="true">
<method event="onclick">
var s =mycombo.getSelectedText();
var ds = canvas.datasets.setQueryParams( {myparam : s} );
ds.doRequest();
Debug.write("combo: "+s)
</method>
</view>
<view y="50">
<simplelayout axis="x"/>
<view name="list" datapath="dset:/dating/user[1-3]">
<view height="20" />
<simplelayout axis="y"/>
<text height="120" width="80" datapath="@id"/>
<image datapath="@Photo"/>
<text x="0" y="100" datapath="@username"/>
</view>
</view>
</canvas>
-------------------------------------------------------
I couldn't able to get the value of variable "s" in the above code .Also i treid to execute your code
<http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=368>
But here also I couldn't able to get the variable "s"
If u give an example code, then it would be great help for us.
Thanks
Mallesh
antun
09-18-2003, 08:23 AM
I couldn't able to get the value of variable "s" in the above code .Also i treid to execute your code
What version of the LPS are you running? I know this works on 1.0.1.
-Antun
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.