Before we start, a little introduction about Openlaszlo. Its a XML and Java scripting based framework for Flash (similar to Flex) in which you can create rich applications from HTML pages to flash files and DHTML. This article mainly caters the Data saving problems using dataset in Openlaszlo 3.3.3 (Don’t know if the problem has been solved in latest version).
Issue:
While saving xml by Posting it to a php or jsp or whatever page, using dataset, data conversion errors are shown. Even though the data gets saved but as an error appeared you will get onerror event hence you can’t really say if the data was saved or not.
Solution:
Pre-requisite:
Dataset:Make sure you have defined a dataset for the purpose of saving data in the following way.
<dataset name=”SendData” request=”false” type=”http” src=”http://www.mysite.com/save.php”>
Request = False so that the data is not requested while initialization (as this data set will be used for saving data)
Type = Http for Http request
Saving Data: Post data to your php, jsp (or any other file) using this sort of code
SendData.setQueryParam(”xml”, xmlString);
SendData.setQueryType(”POST”);
SendData.doRequest();
The xmlString in this code could be another dataset in serialized form like ( var xmlString = anotherDataset.serialize(); ), it should be well formed i.e. no syntax error. The above code makes a request to save.php for saving data. Now you will get an error on debugging console which is data conversion error.
Actual Problem: The problem lies in your php (or any other) page code. SendData is a dataset and is expecting a response which is well formed xml. Your php page is not returning anything and in solo mode response headers can’t be analyzed. The thing you need to do is that just print a well formed response i.e. in my case it will be echo “<ok/>”
When your save is successful you should print valid xml (anything valid would do it) and SendData will get it as its data( verify that by calling SendData.serialize() ).
Upon successful saving print valid xml (this will result in ondata event) and in case of error print nothing or invalid xml (this would result in onerror event fire).
This will solve the problem for you.