openlaszlo simple post code
June 22, 2009
Here’s a little form for sending an XML post in OpenLaszlo. This is a useful little snippet of code, since as if you get one little content header or something wrong, Rails will be unforgiving with its powerful, yet strict implementation of REST.
What the app looks like (enter text in the top, click the button, response is printed in the lower box):
blockquote.code {
font-style: normal;
font-family: Monaco,monospace;
font-size: 10px;
border: solid 1px #aaa;
padding: 6px;
background-color: #eee;
color: inherit;
overflow:auto;
margin: 10px 0px;
}
The code:
<canvas title="Test Post" proxied="false">
<dataset src="http:/projects.xml" name="ds"
ondata="response.setAttribute('text'this.childNodes[0].serialize())"/>
<simplelayout spacing="4"/>
<edittext id="postdata" multiline="true" width="400" height="200"
text='<project> <title>XXX</title> </project>'/>
<button text="post">
<handler name="onclick">
ds.setQueryParam("lzpostbody", postdata.text);
ds.setAttribute("querytype", "POST");
ds.setHeader("Content-Type", "application/xml")
ds.doRequest();
</handler>
</button>
<edittext id="response" multiline="true" width="400" height="280"/>
</canvas>