Antun’s Blog

Notes on OpenLaszlo, LZX and Rich Internet Application Development

Antun’s Blog header image 1

Raw POST Data from OpenLaszlo Datasets

April 7th, 2009 · No Comments

There are three practical ways to get data from a browser client to a web service:

  • Query string parameters in a GET or a POST request.
  • POST parameters.
  • Raw POST data.

The first two are fairly straightforward: A query string is the part of the URL that comes after the question mark. Post parameters (as name/value pairs) can be added to a POST request by calling setQueryParam() on the dataset. If the client needs to send a large block of data to the server (e.g. an XML document) that data can be assigned to a single POST parameter.

The third one is a little more complicated. Essentially, it means all the POST body. i.e. Where the POST parameters would normally live. Older versions of the Flash Player had problems with this, so it was not possible to submit raw POST data with older versions of OpenLaszlo in SOLO mode.

This isn’t an issue today. The Flash Player can submit raw post data. So if you absolutely can’t have even a single POST parameter, you can specify content to be included in the POST body by calling:

dataset.setAttribute("querytype", "POST");
dataset.setQueryParam("lzpostbody", "CONTENT");

Note that the lzpostbody query parameter is a special name that tells OpenLaszlo to use the provided string as the entire POST body. Here’s an example of this in action:


<canvas debug="true" proxied="false">
    <dataset name="ds" src="myService.jsp" type="http" request="false"
             querytype="POST"/>

    <button>Do Request
        <handler name="onclick"><![CDATA[
            var body = '<rawpostbodycontents>Hello, this is some XML.</rawpostbodycontents>';
            ds.setQueryParam("lzpostbody", body);
            ds.doRequest();
        ]]>
        </handler>
    </button>

    <handler name="ondata" reference="ds">
        Debug.write("RESPONSE:", ds.serialize());
    </handler>
</canvas>

You can download the entire source, complete with a JSP that reads and echoes the raw POST data.

→ No CommentsTags: LZX Tips · OpenLaszlo

What’s DHTML Compilation Good For?

March 18th, 2009 · 2 Comments

OpenLaszlo allows you to compile applications to SWF8, SWF9 or DHTML. Recently I’ve heard people ask, “why would you want to compile an application to DHTML?”

When you think about it, that’s not a silly question at all. Regardless of whether you compile an OpenLaszlo application to SWF or DHTML, you’ll have similar benefits and simliar constraints. On the positive side, coding complex and interactive user interfaces is straightforward. You’re using a language that was specificially designed for rich Internet applications (RIAs).

However, many of the problems people associate with SWF - inability to bookmark (what exactly?), lack of search engine exposure, back button integration (you want to try explaining what’s supposed to happen when you click back in a RIA), difficulty of integration with traditional HTML applications - affect DHTML-compiled OpenLaszlo applications too. Thankfully these days, most developers understand that a platform like OpenLaszlo isn’t supposed to replace HTML applications, but instead is intended for a specific type of application that’s difficult, if not impossible, to do with HTML. Think Gliffy.

So if DHTML doesn’t solve some of most long-standing “problems” of Flash, what does it offer? Certainly not media support; in fact SWF-compiled OpenLaszlo applications have more consistent support for PNG, as well as FLV, SWF, MP3.

Surely DHTML-compiled OpenLaszlo applications must offer some other benefits then? Well, they work in Webkit, which means they’ll run on the iPhone (and of course many upcoming mobile devices that use DHTML). That’s definitely an advantage, but the applications are still limited by the performance of the small CPU.

So now we get to where DHTML compilation really shines… Remember how I said that OpenLaszlo was good for some applications, and HTML was good for others? DHTML-compilation in OpenLaszlo allows you to run one or more HTML applications inside your OpenLaszlo application!

How can it do this? By using the <html> tag, you can embed another web property (e.g. a web site, HTML-based application) inside your OpenLaszlo application. Here’s an example that shows two HTML web sites embedded in the same OpenLaszlo application:

Screenshot of two HTML applications in one OpenLaszlo application

Screenshot of two HTML applications in one OpenLaszlo application

Unfortunately, I can’t simply embed this example into my blog, because it relies on the OpenLaszlo wrapper code. You have to click the screenshot above and then play with the windows.

You may be aware that SWF-compilation also supports the <html> tag. However, the problem with using the <html> tag with a SWF-compiled OpenLaszlo application is that the IFRAME which displays the HTML web site will always float above the SWF. That means you can’t really have a windowed application, unless you’re satisfied with only having one window in your entire application. And you can’t have two <html> tags, if they’re likely to ever overlap, since there’s no way to control which is on top at any one point.

As you can see, that’s not a problem for DHTML.

Download the source for this example.

→ 2 CommentsTags: OpenLaszlo · RIAs

Why I should RTFM

March 16th, 2009 · No Comments

A few days ago, I wrote about how to access the named colors in OpenLaszlo 4.2.0. (Where Have All the Colors Gone?) I even wrote a little example showcasing the colors in the lz.colors array. Then Tucker helpfully directed me to a very complete example in the documentation that showed not only the location of the colors, but also a better way of setting colors.

The W3C provides a list of standard CSS colors, and OpenLaszlo now allows you to use those color names as strings when setting colors.

So in addition to being able to say:

myView.setAttribute("bgcolor", lz.colors.cornflowerblue);

… and of course:

myView.setAttribute("bgcolor", 0x6495ed);

… what’s new is that you can also say:

myView.setAttribute("bgcolor", "cornflowerblue");

Notice that the color name is a string, not a variable. Finally, you can also use the pound (#) notation when setting colors in script:

myView.setAttribute("bgcolor", "#6495ed");

Note that when using pound notation, the color value must be a string.

→ No CommentsTags: LZX Tips · OpenLaszlo