Sorry I was vague on that, and I was referring to the t5components
OnEvent mixin
(http://87.193.218.134:8080/t5components/t5c-commons/ref/org/apache/tapestry/commons/mixins/OnEvent.html).
Here's a quick example of ajax-based data retrieval. Note that where I
use hard-coded strings, you'd be using your database information bean
(or whatever). First you need your template:

        <form t:type="form">
            <t:select t:id="mySelect" model="selectOptions"
value="selected" t:mixins="t5components/OnEvent"
                event="change" onCompleteCallback="selectionChanged"/>
            <t:textfield value="port" t:id="dbPort"/>
            <br/><input t:type="submit"/>
        </form>
       
        <script type="text/javascript">
            function selectionChanged(response) {
                $('dbPort').value = response;
            }
        </script>

The first thing to notice is the use of the onevent mixin, and notice
the subsequent parameters (event="change" and
onCompleteCallback="selectionChanged"). The 'event' parameter notifies
the mixin of which client side event it should bind to, while the
'onCompleteCallback' parameter is the name of an in-scope javascript
function that will receive the ajax response from the server. Also
notice our hard-coded script block in which we declare the named handler
'selectionChanged' - in which we set the value of the field by id
'dbPort' (which if you look at the form, you'll see that we created a
textfield with that id). Now the event handler in the page class:

    public StreamResponse onChangeFromMySelect(String value) {
        logger.info(" changed: " + value);
        return new TextStreamResponse("text/plain",
value.equals("Oracle") ? "1521" : "3306");
    }

This is obviously a stupid implementation in that it tests for the
string "Oracle" and returns "1521", other wise "3306" as a plain-text
response, but it shows how to check for what was selected and how to
return something. Now if you fill in the simple missing parts of this,
you'll see that it works by retrieving values from the server based on
the selection in an asynchronous manner. The OnEvent mixin really opens
the door to a much wider potential of data binding, but by itself it
gives you some raw tools to do what you want.

> As for Ajax support being still in the oven, I'm really hoping it's
> coming out soon.
>   
I imagine it will stop baking when web development methodologies stop
changing. I said 'in the oven' because there are still and handful unmet
goals outstanding in the ajax area. There are a few useful things now,
and I'd say you can bet on the fact that the innovative strides in the
ajax part will be as innovative as those in the rest of the framework.

-- 
http://thegodcode.net


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to