Joshua,
here's a very simple example:
Template:
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
<script type="text/javascript" src="${prototype}"></script>
<script type="text/javascript" src="${scriptaculous}"></script>
<body>
<script type="text/javascript">
function handleResponse (xhrResponse)
{
alert (xhrResponse.responseText);
}
function asyncCall ()
{
new Ajax.Request ('${theLink}', {asynchronous:true,
onSuccess:handleResponse});
}
</script>
<button onclick="asyncCall();">Do AJAX Call</button>
</body>
</html>
Class:
public class AjaxPage
{
@Inject
private ComponentResources _resources;
@Inject
@Path("${tapestry.scriptaculous}/prototype.js")
private Asset _prototype;
@Inject
@Path("${tapestry.scriptaculous}/scriptaculous.js")
private Asset _scriptaculous;
/**
* Generates a URI to the server-side function for the XHR
* to use.
*
* @return the link
*/
public String getTheLink ()
{
Link l = _resources.createActionLink ("myAction", false);
return l.toURI();
}
/**
* This is a server-side method called via XHR that returns
* some text.
*
* @return some text
*/
StreamResponse onMyAction ()
{
return new TextStreamResponse ("type/text", "Five bucks below
the
belt. That's how I roll.");
}
/**
* @return the prototype
*/
public Asset getPrototype ()
{
return _prototype;
}
/**
* @param prototype the prototype to set
*/
public void setPrototype (Asset prototype)
{
_prototype = prototype;
}
/**
* @return the scriptaculous
*/
public Asset getScriptaculous ()
{
return _scriptaculous;
}
/**
* @param scriptaculous the scriptaculous to set
*/
public void setScriptaculous (Asset scriptaculous)
{
_scriptaculous = scriptaculous;
}
}
On 6/13/07, Joshua Jackson <[EMAIL PROTECTED]> wrote:
Hi Massimo
Thanks for the response. How do you exatcly implement the response?
What I assume is that you do something like this:
public StreamResponse onAction(){
return new TextStreamResponse("text/xml", "<employees><employee
name=\"joshua\" /></employees>");
}
And then process it with prototype inside your html page?
Or do you have any other approach for this?
Thanks in advance
On 6/13/07, Massimo Lusetti <[EMAIL PROTECTED]> wrote:
> I'm eager to see this implemented but i could say that right now with
> StreamResponse is fairly easy to accomplish this. Thanks to the T5
> flexibility.
--
Let's create a highly maintainable and efficient code
YM!: thejavafreak
Blog: http://www.nagasakti.or.id/roller/joshua/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
"The future is here. It's just not evenly distributed yet."
-- Traditional
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]