From: titash n. <tit...@gm...> - 2006-03-02 10:30:18
|
Thanks everyone for the comments. This was a great help. Kind regards Titash On 3/1/06, Anthony Bargnesi <aba...@gm...> wrote: > > Titash, > > I also use laszlo with eXist. The two ways I have attempted is by > using REST in a GET and POST style. I was not able to get the > POST method to work because the form parameters were being > encoded and it would always error out saying my REST url was > incorrect. However, I was able to do this with a GET method. I > use an XQuery to query a collection and return an xml dataset that > I use in a view for visualization. I will repost with a better code > example but for now look at this: > > <canvas width=3D"100%" height=3D"100%" debug=3D"true"> > <dataset name=3D"testData" request=3D"false" src=3D" > http://localhost:8080/exist/servlet/db/data/restaurants.xml" type=3D"http= "/> > > <simplelayout axis=3D"y" spacing=3D"20"/> > <edittext name=3D"textXQuery" text=3D"Enter XQuery here" width=3D= "400" /> > <button name=3D"btnXQuery" text=3D"Do XQuery" onclick=3D"canvas.r= equestData();"/> > <edittext name=3D"textResponse" width=3D"400" height=3D"300" mult= iline=3D"true" resizable=3D"true" datapath=3D"testData:/restaurants"> > <method name=3D"ondata" event=3D"ondata"> > Debug.write(testData.getPointer().xpathQuery("/re= staurants")); > </method> > > </edittext> > <debug x=3D"0" y=3D"500" width=3D"600" height=3D"150"/> > > <method name=3D"requestData"> > var d=3Dcanvas.datasets.testData > ; > var p=3Dnew LzParam(); > p.addValue("_query", canvas.textXQuery.text, false); > p.addValue("_wrap", "yes", false); > d.setQueryString > (p); > Debug.write("Src - " + d.src); > Debug.write("QueryString - " + d.querystring); > d.doRequest(); > </method> > </canvas> > > > Here the request is made onrequest and not automatically. The XQuery is > specified in the parameter _query. The REST url is specified as the sour= ce > of the dataset. To get POST to work you need to specify the query type. > From the OpenLaszlo docs - > > setQueryType() LzDataset.setQueryType(reqtype) > > Sets the query type of for the datasource to one of "POST" or "GET" by > calling the method of the same name on this dataset's datasource. Note th= at > this controls how the LPS server makes a request of the backend, as well = as > how the client communicates with the LPS > Parameters Name Type Desc reqtype Sring A string -- either "GET" or > "POST". GET is the default. When the type is "POST", the query parameters > will be sent in the request body, encoded as > application/x-www-form-urlencoded If the type is "POST" and there is a > exactly one request parameter and it is named "lzpostbody", it will be us= ed > as the raw request body (unencoded). Use of "lzpostbody" with a request t= hat > has more than one request parameter is undefined. > So in the above example you would need to call d.setQueryType("POST"); > before you call d.doRequest();. Keep in mind though that you will have t= o > play with the query parameters a bit in order to get this to work (if at = all > :)). > > Hope this helps, > > > -Anthony > |