RE: Ajax quesiton

2007-02-04 Thread Portuendo Vestado
Heh, those were exactly the pieces I was looking at.

The problem I saw with IJSONRender is that you couldn't have your page
implement renderComponent(IJSONWriter writer,..); it has to be some new
component that declared it. Then you'd attach a listener to this new
component (IDirect?), build a URL with DirectService, and bind() from the
client side to have the json method called. That's a lot of work (compared
to other things in Tapestry :) ) just to have control over contents of your
Ajax response. But then I'm just being lazy :)

Do you think something like this could work?
 - extra param on @EventListener, say, callback(), which takes the name of a
function on the client to call with the built object (a la Yahoo Json web
services). Or if it's not @EventListener that we're using, just pass it as
another parameter on your DirectLink.
 - have IJSONWriter (or the dojo xml writer) accessible by navigating
IRequestCycle

E.g.:

@EventListener(elements = "myFavoriteDiv", events = "onmouseover", callback
= "myObj.handleJson")
public void watchText(IRequestCycle cycle)
{
 // get json writer, something like:
 // IJSONWriter writer =
(IJSONWriter)cycle.getResponseBuilder().getWriter();
 // etc...
}

Or instead of @EventListener, in your template:
...

When response is done, it looks something like:
myObj.handleJson({"message": "Built on server", "time": "lunch time"});

On the client:

var myObj = {
handleJson: function (jsonResponse) {
//this is called automatically as soon as response is
eval()'ed
alert(jsonResponse.message);
}
}



___ 
Yahoo! Mail - Sempre a melhor opção para você! 
Experimente já e veja as novidades. 
http://br.yahoo.com/mailbeta/tudonovo/
 


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



Re: Ajax quesiton

2007-02-03 Thread andyhot

Yep, we need a proper guide for this... till then I bet you're looking at
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/form/Autocompleter.java

The idea is that if a component implements IJSONRender and a
json render is executing that includes it, then the component's
void renderComponent(IJSONWriter writer, IRequestCycle cycle);
is going to get called. See what the Autocompleter does to find out how 
to add

data to the writer.

Now, when the response comes in, tapestry.loadJson is called... By 
default this doesn't do anything.


So, how do you use the data then?
I see two options:
-) Attach a custom function on tapestry.loadJson, so that you can do 
whatever you want there (hint: dojo.event.connect).
-) Create a client-side widget that fetches json data on its own and 
pass it the url that creates that data. The DirectService

can create that url for you (see the Autocompleter widget).






Portuendo Vestado wrote:

Hello,

I'm looking for a proper way of using built-in Ajax support in T 4.1.1, and
having a bit of a trouble with the following scenario.

I'm trying to push json back down to the client after using DirectLink's (or
any other IDynamicInvoker, e.g. Form) json="true" parameter, or some other
option, like @EventListener. I can't seem to figure out how I could get the
listener method to build json object to return. Also, once the object is
returned, how would I specify a callback function on the client side to deal
with returned data?

T 4.1.1 does make it simple to reload any components after the asynch
request (updateComponents param), but sometimes you want something simpler,
like sending back some data so browser can take care of any changes on
client-side, without having to reload an entire component. I guess I'm
looking for the simplest and most correct way in T4 of implementing JSON-RPC
(http://manual.dojotoolkit.org/WikiHome/DojoDotBook/Book9).

Is there any documentation/articles on T's Ajax, which could help me with
this or any other related cases? I'm basically using the source code as the
guide, but in this way figuring out even simplest things takes a while.

Thanks!



___ 
Yahoo! Mail - Sempre a melhor opção para você! 
Experimente já e veja as novidades. 
http://br.yahoo.com/mailbeta/tudonovo/
 



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


  



--
Andreas Andreou - [EMAIL PROTECTED] - http://andyhot.di.uoa.gr
Tapestry / Tacos developer
Open Source / J2EE Consulting 



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