You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Daniel Jue <te...@gmail.com> on 2013/07/16 01:21:16 UTC

Loading JSON into a JS var

Hi, I'm getting back into Tapestry development, specifically needing to do
some dynamic front end work I haven't attempted before.

I have a 3rd party JS library (Infovis) which draws a graph using JSON data.
http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html

The starter example uses

var json = "...the sample graph data.."

and then later on there is call to

   1. fd.loadJSON(json);


What I'd like to do is have the user click on an action/event link and then
have the var json variable returned from the server side, and then have
fd.loadJSON() called.

What is the most direct and preferred way of doing this? (Preferably
without extra dependencies)


Thanks

Re: Loading JSON into a JS var

Posted by Daniel Jue <te...@gmail.com>.
Hey Thiago, I got it working.  Here is the full working code for
anyone else using T5 + JQuery + ajax

NewAjax.class:

import java.util.Date;

import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;

@Import(library = "context:/js/testJSON.js")
public class NewAjax {
@Inject
private ComponentResources resources;

@Inject
private Request request;

@Inject
private JavaScriptSupport javaScriptSupport;

public String getEventLink() {
return resources.createEventLink("MyCustomEventName").toURI();
}

void afterRender() {
javaScriptSupport.addScript("setupEvent('%s', '%s');", "linkId",
getEventLink());
}

@OnEvent(value = "MyCustomEventName")
JSONObject myEventHandler() {
// check if this is a AJAX request
if (request.isXHR()) {
String queryParameter1 = request.getParameter("queryParameter1");
String queryParameter2 = request.getParameter("queryParameter2");
JSONObject object = new JSONObject();
object.put("var1", "\n" + queryParameter1.toUpperCase());
object.put("var2", "\n" + queryParameter2.toUpperCase());
object.put("message", getMessage());
// Make your real payload
return object;
}
return null;
}

private String getMessage() {
return "SUCCESS at " + (new Date()).toString();
}
}



NewAjax.tml
<html title="New Ajax"
xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">
<body>
<a id="linkId">Click this Tapestry Link</a>
</body>
</html>


testJSON.js:

function setupEvent(id, theurl) {
alert("here with "+"#"+id);
$("#"+id).click(function() {
var dataObj = {};
dataObj["queryParameter1"] = "Daniel";
dataObj["queryParameter2"] = "Jue";
$.ajax({
url : theurl,
data : dataObj,
dataType: "json",
complete : function() {
alert("AJAX - complete setup by T5()");
},
success : function(result) {
alert("AJAX - success setup by T5() " + result.message+result.var1+result.var2);
}
});
});
}


Of special note are the changes to testJSON.js to make it work with JQuery.
The id must have a '#' symbol.  Also the datatype is set to 'json',
but it could be 'html', etc.

Thanks also to Taha and Howard for their input.

On Tue, Jul 16, 2013 at 2:11 PM, Thiago H de Paula Figueiredo
<th...@gmail.com> wrote:
> On Tue, 16 Jul 2013 14:31:27 -0300, Daniel Jue <te...@gmail.com> wrote:
>
>> If it's the javascript that's at fault one thing that may be causing
>> it is that I'm using Tapestry5-JQuery, which requires a different
>> syntax than prototype's 'observe' and 'click'.
>
>
> You used Prototype in the code you posted, so I thought you were using it
> instead of jQuery. Of course, you'll need to adapt the JS part for jQuery.
>
>
> --
> Thiago H. de Paula Figueiredo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loading JSON into a JS var

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 16 Jul 2013 14:31:27 -0300, Daniel Jue <te...@gmail.com> wrote:

> If it's the javascript that's at fault one thing that may be causing
> it is that I'm using Tapestry5-JQuery, which requires a different
> syntax than prototype's 'observe' and 'click'.

You used Prototype in the code you posted, so I thought you were using it  
instead of jQuery. Of course, you'll need to adapt the JS part for jQuery.

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loading JSON into a JS var

Posted by Daniel Jue <te...@gmail.com>.
If it's the javascript that's at fault one thing that may be causing
it is that I'm using Tapestry5-JQuery, which requires a different
syntax than prototype's 'observe' and 'click'.

I'm still trying to figure this out--obviously I'm not a JS expert yet.

On Tue, Jul 16, 2013 at 1:11 PM, Daniel Jue <te...@gmail.com> wrote:
> Thiago, thanks.  I feel that is very close to working.  I've tried out
> that example in a few ways and I still have some issues:
> Without anything in the TML, there is nothing to click on, so I tried
> adding an event link in the tml, like this
>
>
> <a t:type="eventlink" t:event='myCustomEventName' t:id='linkId' id='linkId'>
> Click this
> link to
> generate SUCCESS!
> </a>
>
> In the code you provided, when onMyCustomEventName() is called, there
> is no differentiation that it is an XHR call or not.  That's fine but
> when onMyCustomEventName() returns the JSON, I get
>
> An unexpected application exception has occurred.
> A component event handler method returned the value { "message" :
> "This is the message:SUCCESS" }. Return type
> org.apache.tapestry5.json.JSONObject can not be handled.
>
> The javascript for setupEvent() seems to be initializing ok, in my
> page it's this:
>
> <script type="text/javascript">var $ = jQuery; Tapestry.JQUERY=true;
> Tapestry.onDOMLoaded(function() {
> setupEvent('linkId', /newajax:mycustomeventname);
> });
> </script>
>
>
> So it seems like the javascript itself is not catching the response.
> Is it a problem that there is a ':' in the response url?
> (newajax:mycustomeventname)
>
>
> On Tue, Jul 16, 2013 at 8:58 AM, Thiago H de Paula Figueiredo
> <th...@gmail.com> wrote:
>> You don't need Zone nor EventLink for that, so don't use them. Here's
>> another way (not tested):
>>
>> @Inject
>> private ComponentResources resources;
>>
>> @Inject
>> private Request request;
>>
>> @Inject
>> private JavaScriptSupport javaScriptSupport;
>>
>> public String getEventLink() {
>>         return resources.createEventLink("MyCustomEventName");
>> }
>>
>> void afterRender() {
>>         javaScriptSupport.addScript("setupEvent('%s', %s);", "linkId",
>> getEventLink());
>> }
>>
>> JSONObject onMyCustomEventName() {
>>         String queryParameter1 = request.getParameter("queryParameter1");
>>         String queryParameter2 = request.getParameter("queryParameter2");
>>         JSONObject object = new JSONObject();
>>         object.put("message", getMessage());
>>         (...)
>>         return object;
>> }
>>
>> function setupEvent(id, url) {
>>         $(id).observe("click", function(event) {
>>                 new Ajax.Request(url, {
>>                         onSuccess: function(response) {
>>                                 var returnedObject = response.responseJSON;
>>                                 window.alert(returnedObject);
>>                         },
>>                         parameters : {
>>                                 queryParameter1: 'valueOfqueryParameter1',
>>                                 queryParameter2: 'valueOfqueryParameter2',
>>                         }
>>                 )};
>>         });
>>
>> }
>>
>>
>> On Tue, 16 Jul 2013 02:13:51 -0300, Daniel Jue <te...@gmail.com> wrote:
>>
>>> Ugh, still not working for me yet.  Once I get it though, things should
>>> really get moving.
>>> Here's what I have.  The intent is a simple event link on a page, that,
>>> when click on, performs an ajax call to get a json payload, and then
>>> displays the payload as the contents to a javascript alert().
>>> I figure from this simplified problem I can create real payloads and
>>> assign
>>> them to meaningful javascript variables.
>>>
>>> Something is obviously missing, but I'm at a loss for what.  This is
>>> probably my 20th iteration of it since the last email.  Of note is that in
>>> sendJson(), the request is NOT XHR, even though it's being called from an
>>> event link with a zone.
>>> Any ideas?  I'd really like to just get this working.  It seems like this
>>> would be a very common need, to provide json to js visualizations from
>>> pages without having to stand up separate REST services.  I poked around
>>> in
>>> tapestry5-jquery and tapestry5-highcharts, but didn't see an obvious
>>> example.
>>>
>>> NewAjax.java:
>>>
>>>
>>> @Import(library = "context:/js/testJSON.js")
>>> public class NewAjax {
>>> @Inject
>>> private AjaxResponseRenderer ajaxResponseRenderer;
>>>
>>> @Inject
>>> @Property
>>> private JavaScriptSupport javaScriptSupport;
>>> @Inject
>>> private ComponentResources resources;
>>>
>>> @InjectComponent
>>> private Zone someZone;
>>>
>>> @InjectComponent
>>> private EventLink jsonCallbackLink;
>>>
>>> @AfterRender
>>> private void addJavaScript() {
>>> javaScriptSupport.addInitializerCall("testJSON",
>>> jsonCallbackLink.getClientId());
>>> }
>>>
>>> @Inject
>>> private Request request;
>>>
>>> @OnEvent("sendJSON")
>>> void sendJSON() {
>>> if (request.isXHR()) {
>>> // use AjaxResponseRenderer
>>> ajaxResponseRenderer.addCallback(new JSONCallback() {
>>> public void run(JSONObject reply) {
>>> // generate my custom JSON payload here
>>> reply.put("message", "my message");
>>> }
>>> });
>>> }
>>> }
>>> }
>>>
>>>
>>>
>>> NewAjax.tml
>>>
>>> <html title="New Ajax" xmlns:t="
>>> http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>>> xmlns:p="tapestry:parameter">
>>> <body>
>>> <t:zone t:id='someZone'>
>>> This is someZone
>>> </t:zone>
>>> <a t:type='eventLink' t:zone="someZone" t:id='jsonCallbackLink'
>>> t:event='sendJSON'>
>>> Click this link to generate JSON!
>>> </a>
>>> </body>
>>> </html>
>>>
>>>
>>> testJSON.js:
>>>
>>> Tapestry.Initializer.testJSON = function(elementId){
>>>     $(elementId).observe("click", function(event){
>>>
>>>         Tapestry.ajaxRequest($(elementId).href, function(response){
>>>             alert(response.responseJSON.message);
>>>         });
>>>
>>>         event.preventDefault();
>>>     });
>>> };
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Mon, Jul 15, 2013 at 9:08 PM, Taha Hafeez Siddiqi <
>>> tawus.tapestry@gmail.com> wrote:
>>>
>>>> EventLink must have its zone parameter set to a zone for it to use ajax.
>>>> Remember not to use an empty zone(because of a bug in 5.3). If you want
>>>> to
>>>> use an empty zone just add &nbsp; to it.
>>>>
>>>>
>>>> On 16-Jul-2013, at 6:30 AM, Daniel Jue <te...@gmail.com> wrote:
>>>>
>>>> > Thanks Taha and Howard!  Looks like I have some more learning to do,
>>>> which
>>>> > is always great.
>>>> > BTW, I'm on T5.3.6.
>>>> >
>>>> >
>>>> > Howard, for my purposes the JSON payload for the visualization needs to
>>>> be
>>>> > generated at runtime when the user clicks (I'll eventually have dozens
>>>> > of
>>>> > clickable links, each one a costly calculation)--your solution sounds
>>>> like
>>>> > the json is getting pre-calculated (unless I am interpreting it wrong,
>>>> > which is likely)
>>>> >
>>>> > I was trying one of Taha's old examples that seemed similar (
>>>> >
>>>>
>>>> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Updating-a-page-with-a-JSONObject-td3339940.html
>>>> > )
>>>> > But I'm getting an error with that.  Possibly because I'm trying to
>>>> trigger
>>>> > the Ajax response through an eventlink I added to the TML, with no
>>>> > Zone.
>>>> > Do I need to make use of a zone component at all?  I'm getting an
>>>> > error of "Page
>>>> > must be specified before initializing for partial page render."
>>>> >
>>>> >
>>>> >
>>>> >
>>>> > On Mon, Jul 15, 2013 at 7:30 PM, Howard Lewis Ship <hl...@gmail.com>
>>>> wrote:
>>>> >
>>>> >> Build a URL using resources.createEventLink() and pass this down to
>>>> >> the
>>>> >> browser.
>>>> >>
>>>> >> From the event handler, construct and return a JSONObject.
>>>> >>
>>>> >> Have the client trigger the provided URL, then pass the response.json
>>>> >> to
>>>> >> the fd.loadJSON() method.
>>>> >>
>>>> >> There's a bunch of other variations on this; for instance, you can
>>>> create a
>>>> >> initializer function (in 5.3) or a module (in 5.4) and pass the JSON
>>>> object
>>>> >> to the initalize function, or the module, via JavaScriptSupport.
>>>> >>
>>>> >>
>>>> >> On Mon, Jul 15, 2013 at 4:21 PM, Daniel Jue <te...@gmail.com>
>>>> >> wrote:
>>>> >>
>>>> >>> Hi, I'm getting back into Tapestry development, specifically needing
>>>> >>> to
>>>> >> do
>>>> >>> some dynamic front end work I haven't attempted before.
>>>> >>>
>>>> >>> I have a 3rd party JS library (Infovis) which draws a graph using
>>>> >>> JSON
>>>> >>> data.
>>>> >>>
>>>> >>>
>>>> >>
>>>>
>>>> http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html
>>>> >>>
>>>> >>> The starter example uses
>>>> >>>
>>>> >>> var json = "...the sample graph data.."
>>>> >>>
>>>> >>> and then later on there is call to
>>>> >>>
>>>> >>>   1. fd.loadJSON(json);
>>>> >>>
>>>> >>>
>>>> >>> What I'd like to do is have the user click on an action/event link
>>>> >>> and
>>>> >> then
>>>> >>> have the var json variable returned from the server side, and then
>>>> >>> have
>>>> >>> fd.loadJSON() called.
>>>> >>>
>>>> >>> What is the most direct and preferred way of doing this? (Preferably
>>>> >>> without extra dependencies)
>>>> >>>
>>>> >>>
>>>> >>> Thanks
>>>> >>>
>>>> >>
>>>> >>
>>>> >>
>>>> >> --
>>>> >> Howard M. Lewis Ship
>>>> >>
>>>> >> Creator of Apache Tapestry
>>>> >>
>>>> >> The source for Tapestry training, mentoring and support. Contact me to
>>>> >> learn how I can get you up and productive in Tapestry fast!
>>>> >>
>>>> >> (971) 678-5210
>>>> >> http://howardlewisship.com
>>>> >>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>>
>>>>
>>
>>
>> --
>> Thiago H. de Paula Figueiredo
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loading JSON into a JS var

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 16 Jul 2013 14:11:51 -0300, Daniel Jue <te...@gmail.com> wrote:

> Thiago, thanks.  I feel that is very close to working.  I've tried out
> that example in a few ways and I still have some issues:
> Without anything in the TML, there is nothing to click on, so I tried
> adding an event link in the tml, like this
>
>
> <a t:type="eventlink" t:event='myCustomEventName' t:id='linkId'  
> id='linkId'>

I'm sorry, I forgot to mention that your template should have some link  
with id 'linkId'.
As I said, you shouldn't use EventLink in this case, as you're doing the  
wiring yourself. It should be an ordinary HTML link:

<a id="linkId">...</a>

-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loading JSON into a JS var

Posted by Daniel Jue <te...@gmail.com>.
Thiago, thanks.  I feel that is very close to working.  I've tried out
that example in a few ways and I still have some issues:
Without anything in the TML, there is nothing to click on, so I tried
adding an event link in the tml, like this


<a t:type="eventlink" t:event='myCustomEventName' t:id='linkId' id='linkId'>
Click this
link to
generate SUCCESS!
</a>

In the code you provided, when onMyCustomEventName() is called, there
is no differentiation that it is an XHR call or not.  That's fine but
when onMyCustomEventName() returns the JSON, I get

An unexpected application exception has occurred.
A component event handler method returned the value { "message" :
"This is the message:SUCCESS" }. Return type
org.apache.tapestry5.json.JSONObject can not be handled.

The javascript for setupEvent() seems to be initializing ok, in my
page it's this:

<script type="text/javascript">var $ = jQuery; Tapestry.JQUERY=true;
Tapestry.onDOMLoaded(function() {
setupEvent('linkId', /newajax:mycustomeventname);
});
</script>


So it seems like the javascript itself is not catching the response.
Is it a problem that there is a ':' in the response url?
(newajax:mycustomeventname)


On Tue, Jul 16, 2013 at 8:58 AM, Thiago H de Paula Figueiredo
<th...@gmail.com> wrote:
> You don't need Zone nor EventLink for that, so don't use them. Here's
> another way (not tested):
>
> @Inject
> private ComponentResources resources;
>
> @Inject
> private Request request;
>
> @Inject
> private JavaScriptSupport javaScriptSupport;
>
> public String getEventLink() {
>         return resources.createEventLink("MyCustomEventName");
> }
>
> void afterRender() {
>         javaScriptSupport.addScript("setupEvent('%s', %s);", "linkId",
> getEventLink());
> }
>
> JSONObject onMyCustomEventName() {
>         String queryParameter1 = request.getParameter("queryParameter1");
>         String queryParameter2 = request.getParameter("queryParameter2");
>         JSONObject object = new JSONObject();
>         object.put("message", getMessage());
>         (...)
>         return object;
> }
>
> function setupEvent(id, url) {
>         $(id).observe("click", function(event) {
>                 new Ajax.Request(url, {
>                         onSuccess: function(response) {
>                                 var returnedObject = response.responseJSON;
>                                 window.alert(returnedObject);
>                         },
>                         parameters : {
>                                 queryParameter1: 'valueOfqueryParameter1',
>                                 queryParameter2: 'valueOfqueryParameter2',
>                         }
>                 )};
>         });
>
> }
>
>
> On Tue, 16 Jul 2013 02:13:51 -0300, Daniel Jue <te...@gmail.com> wrote:
>
>> Ugh, still not working for me yet.  Once I get it though, things should
>> really get moving.
>> Here's what I have.  The intent is a simple event link on a page, that,
>> when click on, performs an ajax call to get a json payload, and then
>> displays the payload as the contents to a javascript alert().
>> I figure from this simplified problem I can create real payloads and
>> assign
>> them to meaningful javascript variables.
>>
>> Something is obviously missing, but I'm at a loss for what.  This is
>> probably my 20th iteration of it since the last email.  Of note is that in
>> sendJson(), the request is NOT XHR, even though it's being called from an
>> event link with a zone.
>> Any ideas?  I'd really like to just get this working.  It seems like this
>> would be a very common need, to provide json to js visualizations from
>> pages without having to stand up separate REST services.  I poked around
>> in
>> tapestry5-jquery and tapestry5-highcharts, but didn't see an obvious
>> example.
>>
>> NewAjax.java:
>>
>>
>> @Import(library = "context:/js/testJSON.js")
>> public class NewAjax {
>> @Inject
>> private AjaxResponseRenderer ajaxResponseRenderer;
>>
>> @Inject
>> @Property
>> private JavaScriptSupport javaScriptSupport;
>> @Inject
>> private ComponentResources resources;
>>
>> @InjectComponent
>> private Zone someZone;
>>
>> @InjectComponent
>> private EventLink jsonCallbackLink;
>>
>> @AfterRender
>> private void addJavaScript() {
>> javaScriptSupport.addInitializerCall("testJSON",
>> jsonCallbackLink.getClientId());
>> }
>>
>> @Inject
>> private Request request;
>>
>> @OnEvent("sendJSON")
>> void sendJSON() {
>> if (request.isXHR()) {
>> // use AjaxResponseRenderer
>> ajaxResponseRenderer.addCallback(new JSONCallback() {
>> public void run(JSONObject reply) {
>> // generate my custom JSON payload here
>> reply.put("message", "my message");
>> }
>> });
>> }
>> }
>> }
>>
>>
>>
>> NewAjax.tml
>>
>> <html title="New Ajax" xmlns:t="
>> http://tapestry.apache.org/schema/tapestry_5_3.xsd"
>> xmlns:p="tapestry:parameter">
>> <body>
>> <t:zone t:id='someZone'>
>> This is someZone
>> </t:zone>
>> <a t:type='eventLink' t:zone="someZone" t:id='jsonCallbackLink'
>> t:event='sendJSON'>
>> Click this link to generate JSON!
>> </a>
>> </body>
>> </html>
>>
>>
>> testJSON.js:
>>
>> Tapestry.Initializer.testJSON = function(elementId){
>>     $(elementId).observe("click", function(event){
>>
>>         Tapestry.ajaxRequest($(elementId).href, function(response){
>>             alert(response.responseJSON.message);
>>         });
>>
>>         event.preventDefault();
>>     });
>> };
>>
>>
>>
>>
>>
>>
>>
>>
>> On Mon, Jul 15, 2013 at 9:08 PM, Taha Hafeez Siddiqi <
>> tawus.tapestry@gmail.com> wrote:
>>
>>> EventLink must have its zone parameter set to a zone for it to use ajax.
>>> Remember not to use an empty zone(because of a bug in 5.3). If you want
>>> to
>>> use an empty zone just add &nbsp; to it.
>>>
>>>
>>> On 16-Jul-2013, at 6:30 AM, Daniel Jue <te...@gmail.com> wrote:
>>>
>>> > Thanks Taha and Howard!  Looks like I have some more learning to do,
>>> which
>>> > is always great.
>>> > BTW, I'm on T5.3.6.
>>> >
>>> >
>>> > Howard, for my purposes the JSON payload for the visualization needs to
>>> be
>>> > generated at runtime when the user clicks (I'll eventually have dozens
>>> > of
>>> > clickable links, each one a costly calculation)--your solution sounds
>>> like
>>> > the json is getting pre-calculated (unless I am interpreting it wrong,
>>> > which is likely)
>>> >
>>> > I was trying one of Taha's old examples that seemed similar (
>>> >
>>>
>>> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Updating-a-page-with-a-JSONObject-td3339940.html
>>> > )
>>> > But I'm getting an error with that.  Possibly because I'm trying to
>>> trigger
>>> > the Ajax response through an eventlink I added to the TML, with no
>>> > Zone.
>>> > Do I need to make use of a zone component at all?  I'm getting an
>>> > error of "Page
>>> > must be specified before initializing for partial page render."
>>> >
>>> >
>>> >
>>> >
>>> > On Mon, Jul 15, 2013 at 7:30 PM, Howard Lewis Ship <hl...@gmail.com>
>>> wrote:
>>> >
>>> >> Build a URL using resources.createEventLink() and pass this down to
>>> >> the
>>> >> browser.
>>> >>
>>> >> From the event handler, construct and return a JSONObject.
>>> >>
>>> >> Have the client trigger the provided URL, then pass the response.json
>>> >> to
>>> >> the fd.loadJSON() method.
>>> >>
>>> >> There's a bunch of other variations on this; for instance, you can
>>> create a
>>> >> initializer function (in 5.3) or a module (in 5.4) and pass the JSON
>>> object
>>> >> to the initalize function, or the module, via JavaScriptSupport.
>>> >>
>>> >>
>>> >> On Mon, Jul 15, 2013 at 4:21 PM, Daniel Jue <te...@gmail.com>
>>> >> wrote:
>>> >>
>>> >>> Hi, I'm getting back into Tapestry development, specifically needing
>>> >>> to
>>> >> do
>>> >>> some dynamic front end work I haven't attempted before.
>>> >>>
>>> >>> I have a 3rd party JS library (Infovis) which draws a graph using
>>> >>> JSON
>>> >>> data.
>>> >>>
>>> >>>
>>> >>
>>>
>>> http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html
>>> >>>
>>> >>> The starter example uses
>>> >>>
>>> >>> var json = "...the sample graph data.."
>>> >>>
>>> >>> and then later on there is call to
>>> >>>
>>> >>>   1. fd.loadJSON(json);
>>> >>>
>>> >>>
>>> >>> What I'd like to do is have the user click on an action/event link
>>> >>> and
>>> >> then
>>> >>> have the var json variable returned from the server side, and then
>>> >>> have
>>> >>> fd.loadJSON() called.
>>> >>>
>>> >>> What is the most direct and preferred way of doing this? (Preferably
>>> >>> without extra dependencies)
>>> >>>
>>> >>>
>>> >>> Thanks
>>> >>>
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> Howard M. Lewis Ship
>>> >>
>>> >> Creator of Apache Tapestry
>>> >>
>>> >> The source for Tapestry training, mentoring and support. Contact me to
>>> >> learn how I can get you up and productive in Tapestry fast!
>>> >>
>>> >> (971) 678-5210
>>> >> http://howardlewisship.com
>>> >>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>
>
> --
> Thiago H. de Paula Figueiredo
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loading JSON into a JS var

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
You don't need Zone nor EventLink for that, so don't use them. Here's  
another way (not tested):

@Inject
private ComponentResources resources;

@Inject
private Request request;

@Inject
private JavaScriptSupport javaScriptSupport;

public String getEventLink() {
         return resources.createEventLink("MyCustomEventName");
}

void afterRender() {
	javaScriptSupport.addScript("setupEvent('%s', %s);", "linkId",  
getEventLink());
}

JSONObject onMyCustomEventName() {
	String queryParameter1 = request.getParameter("queryParameter1");
	String queryParameter2 = request.getParameter("queryParameter2");
         JSONObject object = new JSONObject();
	object.put("message", getMessage());
	(...)
	return object;
}

function setupEvent(id, url) {
	$(id).observe("click", function(event) {
		new Ajax.Request(url, {
			onSuccess: function(response) {
				var returnedObject = response.responseJSON;
				window.alert(returnedObject);
			},
			parameters : {
				queryParameter1: 'valueOfqueryParameter1',
				queryParameter2: 'valueOfqueryParameter2',
			}
		)};
	});
}


On Tue, 16 Jul 2013 02:13:51 -0300, Daniel Jue <te...@gmail.com> wrote:

> Ugh, still not working for me yet.  Once I get it though, things should
> really get moving.
> Here's what I have.  The intent is a simple event link on a page, that,
> when click on, performs an ajax call to get a json payload, and then
> displays the payload as the contents to a javascript alert().
> I figure from this simplified problem I can create real payloads and  
> assign
> them to meaningful javascript variables.
>
> Something is obviously missing, but I'm at a loss for what.  This is
> probably my 20th iteration of it since the last email.  Of note is that  
> in
> sendJson(), the request is NOT XHR, even though it's being called from an
> event link with a zone.
> Any ideas?  I'd really like to just get this working.  It seems like this
> would be a very common need, to provide json to js visualizations from
> pages without having to stand up separate REST services.  I poked around  
> in
> tapestry5-jquery and tapestry5-highcharts, but didn't see an obvious
> example.
>
> NewAjax.java:
>
>
> @Import(library = "context:/js/testJSON.js")
> public class NewAjax {
> @Inject
> private AjaxResponseRenderer ajaxResponseRenderer;
>
> @Inject
> @Property
> private JavaScriptSupport javaScriptSupport;
> @Inject
> private ComponentResources resources;
>
> @InjectComponent
> private Zone someZone;
>
> @InjectComponent
> private EventLink jsonCallbackLink;
>
> @AfterRender
> private void addJavaScript() {
> javaScriptSupport.addInitializerCall("testJSON",
> jsonCallbackLink.getClientId());
> }
>
> @Inject
> private Request request;
>
> @OnEvent("sendJSON")
> void sendJSON() {
> if (request.isXHR()) {
> // use AjaxResponseRenderer
> ajaxResponseRenderer.addCallback(new JSONCallback() {
> public void run(JSONObject reply) {
> // generate my custom JSON payload here
> reply.put("message", "my message");
> }
> });
> }
> }
> }
>
>
>
> NewAjax.tml
>
> <html title="New Ajax" xmlns:t="
> http://tapestry.apache.org/schema/tapestry_5_3.xsd"
> xmlns:p="tapestry:parameter">
> <body>
> <t:zone t:id='someZone'>
> This is someZone
> </t:zone>
> <a t:type='eventLink' t:zone="someZone" t:id='jsonCallbackLink'
> t:event='sendJSON'>
> Click this link to generate JSON!
> </a>
> </body>
> </html>
>
>
> testJSON.js:
>
> Tapestry.Initializer.testJSON = function(elementId){
>     $(elementId).observe("click", function(event){
>
>         Tapestry.ajaxRequest($(elementId).href, function(response){
>             alert(response.responseJSON.message);
>         });
>
>         event.preventDefault();
>     });
> };
>
>
>
>
>
>
>
>
> On Mon, Jul 15, 2013 at 9:08 PM, Taha Hafeez Siddiqi <
> tawus.tapestry@gmail.com> wrote:
>
>> EventLink must have its zone parameter set to a zone for it to use ajax.
>> Remember not to use an empty zone(because of a bug in 5.3). If you want  
>> to
>> use an empty zone just add &nbsp; to it.
>>
>>
>> On 16-Jul-2013, at 6:30 AM, Daniel Jue <te...@gmail.com> wrote:
>>
>> > Thanks Taha and Howard!  Looks like I have some more learning to do,
>> which
>> > is always great.
>> > BTW, I'm on T5.3.6.
>> >
>> >
>> > Howard, for my purposes the JSON payload for the visualization needs  
>> to
>> be
>> > generated at runtime when the user clicks (I'll eventually have  
>> dozens of
>> > clickable links, each one a costly calculation)--your solution sounds
>> like
>> > the json is getting pre-calculated (unless I am interpreting it wrong,
>> > which is likely)
>> >
>> > I was trying one of Taha's old examples that seemed similar (
>> >
>> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Updating-a-page-with-a-JSONObject-td3339940.html
>> > )
>> > But I'm getting an error with that.  Possibly because I'm trying to
>> trigger
>> > the Ajax response through an eventlink I added to the TML, with no  
>> Zone.
>> > Do I need to make use of a zone component at all?  I'm getting an
>> > error of "Page
>> > must be specified before initializing for partial page render."
>> >
>> >
>> >
>> >
>> > On Mon, Jul 15, 2013 at 7:30 PM, Howard Lewis Ship <hl...@gmail.com>
>> wrote:
>> >
>> >> Build a URL using resources.createEventLink() and pass this down to  
>> the
>> >> browser.
>> >>
>> >> From the event handler, construct and return a JSONObject.
>> >>
>> >> Have the client trigger the provided URL, then pass the  
>> response.json to
>> >> the fd.loadJSON() method.
>> >>
>> >> There's a bunch of other variations on this; for instance, you can
>> create a
>> >> initializer function (in 5.3) or a module (in 5.4) and pass the JSON
>> object
>> >> to the initalize function, or the module, via JavaScriptSupport.
>> >>
>> >>
>> >> On Mon, Jul 15, 2013 at 4:21 PM, Daniel Jue <te...@gmail.com>  
>> wrote:
>> >>
>> >>> Hi, I'm getting back into Tapestry development, specifically  
>> needing to
>> >> do
>> >>> some dynamic front end work I haven't attempted before.
>> >>>
>> >>> I have a 3rd party JS library (Infovis) which draws a graph using  
>> JSON
>> >>> data.
>> >>>
>> >>>
>> >>
>> http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html
>> >>>
>> >>> The starter example uses
>> >>>
>> >>> var json = "...the sample graph data.."
>> >>>
>> >>> and then later on there is call to
>> >>>
>> >>>   1. fd.loadJSON(json);
>> >>>
>> >>>
>> >>> What I'd like to do is have the user click on an action/event link  
>> and
>> >> then
>> >>> have the var json variable returned from the server side, and then  
>> have
>> >>> fd.loadJSON() called.
>> >>>
>> >>> What is the most direct and preferred way of doing this? (Preferably
>> >>> without extra dependencies)
>> >>>
>> >>>
>> >>> Thanks
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Howard M. Lewis Ship
>> >>
>> >> Creator of Apache Tapestry
>> >>
>> >> The source for Tapestry training, mentoring and support. Contact me  
>> to
>> >> learn how I can get you up and productive in Tapestry fast!
>> >>
>> >> (971) 678-5210
>> >> http://howardlewisship.com
>> >>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>


-- 
Thiago H. de Paula Figueiredo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loading JSON into a JS var

Posted by Daniel Jue <te...@gmail.com>.
Ugh, still not working for me yet.  Once I get it though, things should
really get moving.
Here's what I have.  The intent is a simple event link on a page, that,
when click on, performs an ajax call to get a json payload, and then
displays the payload as the contents to a javascript alert().
I figure from this simplified problem I can create real payloads and assign
them to meaningful javascript variables.

Something is obviously missing, but I'm at a loss for what.  This is
probably my 20th iteration of it since the last email.  Of note is that in
sendJson(), the request is NOT XHR, even though it's being called from an
event link with a zone.
Any ideas?  I'd really like to just get this working.  It seems like this
would be a very common need, to provide json to js visualizations from
pages without having to stand up separate REST services.  I poked around in
tapestry5-jquery and tapestry5-highcharts, but didn't see an obvious
example.

NewAjax.java:


@Import(library = "context:/js/testJSON.js")
public class NewAjax {
@Inject
private AjaxResponseRenderer ajaxResponseRenderer;

@Inject
@Property
private JavaScriptSupport javaScriptSupport;
@Inject
private ComponentResources resources;

@InjectComponent
private Zone someZone;

@InjectComponent
private EventLink jsonCallbackLink;

@AfterRender
private void addJavaScript() {
javaScriptSupport.addInitializerCall("testJSON",
jsonCallbackLink.getClientId());
}

@Inject
private Request request;

@OnEvent("sendJSON")
void sendJSON() {
if (request.isXHR()) {
// use AjaxResponseRenderer
ajaxResponseRenderer.addCallback(new JSONCallback() {
public void run(JSONObject reply) {
// generate my custom JSON payload here
reply.put("message", "my message");
}
});
}
}
}



NewAjax.tml

<html title="New Ajax" xmlns:t="
http://tapestry.apache.org/schema/tapestry_5_3.xsd"
xmlns:p="tapestry:parameter">
<body>
<t:zone t:id='someZone'>
This is someZone
</t:zone>
<a t:type='eventLink' t:zone="someZone" t:id='jsonCallbackLink'
t:event='sendJSON'>
Click this link to generate JSON!
</a>
</body>
</html>


testJSON.js:

Tapestry.Initializer.testJSON = function(elementId){
    $(elementId).observe("click", function(event){

        Tapestry.ajaxRequest($(elementId).href, function(response){
            alert(response.responseJSON.message);
        });

        event.preventDefault();
    });
};








On Mon, Jul 15, 2013 at 9:08 PM, Taha Hafeez Siddiqi <
tawus.tapestry@gmail.com> wrote:

> EventLink must have its zone parameter set to a zone for it to use ajax.
> Remember not to use an empty zone(because of a bug in 5.3). If you want to
> use an empty zone just add &nbsp; to it.
>
>
> On 16-Jul-2013, at 6:30 AM, Daniel Jue <te...@gmail.com> wrote:
>
> > Thanks Taha and Howard!  Looks like I have some more learning to do,
> which
> > is always great.
> > BTW, I'm on T5.3.6.
> >
> >
> > Howard, for my purposes the JSON payload for the visualization needs to
> be
> > generated at runtime when the user clicks (I'll eventually have dozens of
> > clickable links, each one a costly calculation)--your solution sounds
> like
> > the json is getting pre-calculated (unless I am interpreting it wrong,
> > which is likely)
> >
> > I was trying one of Taha's old examples that seemed similar (
> >
> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Updating-a-page-with-a-JSONObject-td3339940.html
> > )
> > But I'm getting an error with that.  Possibly because I'm trying to
> trigger
> > the Ajax response through an eventlink I added to the TML, with no Zone.
> > Do I need to make use of a zone component at all?  I'm getting an
> > error of "Page
> > must be specified before initializing for partial page render."
> >
> >
> >
> >
> > On Mon, Jul 15, 2013 at 7:30 PM, Howard Lewis Ship <hl...@gmail.com>
> wrote:
> >
> >> Build a URL using resources.createEventLink() and pass this down to the
> >> browser.
> >>
> >> From the event handler, construct and return a JSONObject.
> >>
> >> Have the client trigger the provided URL, then pass the response.json to
> >> the fd.loadJSON() method.
> >>
> >> There's a bunch of other variations on this; for instance, you can
> create a
> >> initializer function (in 5.3) or a module (in 5.4) and pass the JSON
> object
> >> to the initalize function, or the module, via JavaScriptSupport.
> >>
> >>
> >> On Mon, Jul 15, 2013 at 4:21 PM, Daniel Jue <te...@gmail.com> wrote:
> >>
> >>> Hi, I'm getting back into Tapestry development, specifically needing to
> >> do
> >>> some dynamic front end work I haven't attempted before.
> >>>
> >>> I have a 3rd party JS library (Infovis) which draws a graph using JSON
> >>> data.
> >>>
> >>>
> >>
> http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html
> >>>
> >>> The starter example uses
> >>>
> >>> var json = "...the sample graph data.."
> >>>
> >>> and then later on there is call to
> >>>
> >>>   1. fd.loadJSON(json);
> >>>
> >>>
> >>> What I'd like to do is have the user click on an action/event link and
> >> then
> >>> have the var json variable returned from the server side, and then have
> >>> fd.loadJSON() called.
> >>>
> >>> What is the most direct and preferred way of doing this? (Preferably
> >>> without extra dependencies)
> >>>
> >>>
> >>> Thanks
> >>>
> >>
> >>
> >>
> >> --
> >> Howard M. Lewis Ship
> >>
> >> Creator of Apache Tapestry
> >>
> >> The source for Tapestry training, mentoring and support. Contact me to
> >> learn how I can get you up and productive in Tapestry fast!
> >>
> >> (971) 678-5210
> >> http://howardlewisship.com
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Loading JSON into a JS var

Posted by Taha Hafeez Siddiqi <ta...@gmail.com>.
EventLink must have its zone parameter set to a zone for it to use ajax. Remember not to use an empty zone(because of a bug in 5.3). If you want to use an empty zone just add &nbsp; to it.


On 16-Jul-2013, at 6:30 AM, Daniel Jue <te...@gmail.com> wrote:

> Thanks Taha and Howard!  Looks like I have some more learning to do, which
> is always great.
> BTW, I'm on T5.3.6.
> 
> 
> Howard, for my purposes the JSON payload for the visualization needs to be
> generated at runtime when the user clicks (I'll eventually have dozens of
> clickable links, each one a costly calculation)--your solution sounds like
> the json is getting pre-calculated (unless I am interpreting it wrong,
> which is likely)
> 
> I was trying one of Taha's old examples that seemed similar (
> http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Updating-a-page-with-a-JSONObject-td3339940.html
> )
> But I'm getting an error with that.  Possibly because I'm trying to trigger
> the Ajax response through an eventlink I added to the TML, with no Zone.
> Do I need to make use of a zone component at all?  I'm getting an
> error of "Page
> must be specified before initializing for partial page render."
> 
> 
> 
> 
> On Mon, Jul 15, 2013 at 7:30 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
> 
>> Build a URL using resources.createEventLink() and pass this down to the
>> browser.
>> 
>> From the event handler, construct and return a JSONObject.
>> 
>> Have the client trigger the provided URL, then pass the response.json to
>> the fd.loadJSON() method.
>> 
>> There's a bunch of other variations on this; for instance, you can create a
>> initializer function (in 5.3) or a module (in 5.4) and pass the JSON object
>> to the initalize function, or the module, via JavaScriptSupport.
>> 
>> 
>> On Mon, Jul 15, 2013 at 4:21 PM, Daniel Jue <te...@gmail.com> wrote:
>> 
>>> Hi, I'm getting back into Tapestry development, specifically needing to
>> do
>>> some dynamic front end work I haven't attempted before.
>>> 
>>> I have a 3rd party JS library (Infovis) which draws a graph using JSON
>>> data.
>>> 
>>> 
>> http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html
>>> 
>>> The starter example uses
>>> 
>>> var json = "...the sample graph data.."
>>> 
>>> and then later on there is call to
>>> 
>>>   1. fd.loadJSON(json);
>>> 
>>> 
>>> What I'd like to do is have the user click on an action/event link and
>> then
>>> have the var json variable returned from the server side, and then have
>>> fd.loadJSON() called.
>>> 
>>> What is the most direct and preferred way of doing this? (Preferably
>>> without extra dependencies)
>>> 
>>> 
>>> Thanks
>>> 
>> 
>> 
>> 
>> --
>> Howard M. Lewis Ship
>> 
>> Creator of Apache Tapestry
>> 
>> The source for Tapestry training, mentoring and support. Contact me to
>> learn how I can get you up and productive in Tapestry fast!
>> 
>> (971) 678-5210
>> http://howardlewisship.com
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: Loading JSON into a JS var

Posted by Daniel Jue <te...@gmail.com>.
Thanks Taha and Howard!  Looks like I have some more learning to do, which
is always great.
BTW, I'm on T5.3.6.


Howard, for my purposes the JSON payload for the visualization needs to be
generated at runtime when the user clicks (I'll eventually have dozens of
clickable links, each one a costly calculation)--your solution sounds like
the json is getting pre-calculated (unless I am interpreting it wrong,
which is likely)

I was trying one of Taha's old examples that seemed similar (
http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/Updating-a-page-with-a-JSONObject-td3339940.html
)
But I'm getting an error with that.  Possibly because I'm trying to trigger
the Ajax response through an eventlink I added to the TML, with no Zone.
Do I need to make use of a zone component at all?  I'm getting an
error of "Page
must be specified before initializing for partial page render."




On Mon, Jul 15, 2013 at 7:30 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> Build a URL using resources.createEventLink() and pass this down to the
> browser.
>
> From the event handler, construct and return a JSONObject.
>
> Have the client trigger the provided URL, then pass the response.json to
> the fd.loadJSON() method.
>
> There's a bunch of other variations on this; for instance, you can create a
> initializer function (in 5.3) or a module (in 5.4) and pass the JSON object
> to the initalize function, or the module, via JavaScriptSupport.
>
>
> On Mon, Jul 15, 2013 at 4:21 PM, Daniel Jue <te...@gmail.com> wrote:
>
> > Hi, I'm getting back into Tapestry development, specifically needing to
> do
> > some dynamic front end work I haven't attempted before.
> >
> > I have a 3rd party JS library (Infovis) which draws a graph using JSON
> > data.
> >
> >
> http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html
> >
> > The starter example uses
> >
> > var json = "...the sample graph data.."
> >
> > and then later on there is call to
> >
> >    1. fd.loadJSON(json);
> >
> >
> > What I'd like to do is have the user click on an action/event link and
> then
> > have the var json variable returned from the server side, and then have
> > fd.loadJSON() called.
> >
> > What is the most direct and preferred way of doing this? (Preferably
> > without extra dependencies)
> >
> >
> > Thanks
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator of Apache Tapestry
>
> The source for Tapestry training, mentoring and support. Contact me to
> learn how I can get you up and productive in Tapestry fast!
>
> (971) 678-5210
> http://howardlewisship.com
>

Re: Loading JSON into a JS var

Posted by Howard Lewis Ship <hl...@gmail.com>.
Build a URL using resources.createEventLink() and pass this down to the
browser.

>From the event handler, construct and return a JSONObject.

Have the client trigger the provided URL, then pass the response.json to
the fd.loadJSON() method.

There's a bunch of other variations on this; for instance, you can create a
initializer function (in 5.3) or a module (in 5.4) and pass the JSON object
to the initalize function, or the module, via JavaScriptSupport.


On Mon, Jul 15, 2013 at 4:21 PM, Daniel Jue <te...@gmail.com> wrote:

> Hi, I'm getting back into Tapestry development, specifically needing to do
> some dynamic front end work I haven't attempted before.
>
> I have a 3rd party JS library (Infovis) which draws a graph using JSON
> data.
>
> http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html
>
> The starter example uses
>
> var json = "...the sample graph data.."
>
> and then later on there is call to
>
>    1. fd.loadJSON(json);
>
>
> What I'd like to do is have the user click on an action/event link and then
> have the var json variable returned from the server side, and then have
> fd.loadJSON() called.
>
> What is the most direct and preferred way of doing this? (Preferably
> without extra dependencies)
>
>
> Thanks
>



-- 
Howard M. Lewis Ship

Creator of Apache Tapestry

The source for Tapestry training, mentoring and support. Contact me to
learn how I can get you up and productive in Tapestry fast!

(971) 678-5210
http://howardlewisship.com

Re: Loading JSON into a JS var

Posted by Taha Hafeez Siddiqi <ta...@gmail.com>.
Hi

You can use AjaxResponseRenderer and pass the variable to an initializer method (which you have to write in javascript).

@Inject
private AjaxResponseRenderer ajaxResponseRenderer;

@OnEvent("eventLinkEventName")
void myEventHandler(){
   ajaxResponseRenderer.addCallback(new JavaScriptCallback(){
   
       public void run(JavaScriptSupport javascriptSupport){
          JSONObject spec = new JSONObject();
          fill_spec_with_json();
          javaScriptSupport.addInitializerCall("MyInitializerMethod", spec);
       }

   });
}




P.S. : Code Not Tested

regards
Taha

On 16-Jul-2013, at 4:51 AM, Daniel Jue <te...@gmail.com> wrote:

> Hi, I'm getting back into Tapestry development, specifically needing to do
> some dynamic front end work I haven't attempted before.
> 
> I have a 3rd party JS library (Infovis) which draws a graph using JSON data.
> http://philogb.github.io/jit/static/v20/Jit/Examples/ForceDirected/example1.html
> 
> The starter example uses
> 
> var json = "...the sample graph data.."
> 
> and then later on there is call to
> 
>   1. fd.loadJSON(json);
> 
> 
> What I'd like to do is have the user click on an action/event link and then
> have the var json variable returned from the server side, and then have
> fd.loadJSON() called.
> 
> What is the most direct and preferred way of doing this? (Preferably
> without extra dependencies)
> 
> 
> Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org