You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by john c <jo...@yahoo.com> on 2014/03/20 14:15:05 UTC

How to Declare JSONObject function ?

With <t:jquery.Draggable /> you can specify the JSONObject params like so: t:params="params"
In Java I have code like this (snippet):

public JSONObject getParams() {
JSONObject options = new JSONObject();
......
......
options.put("start", "function() {$(this).hide();}");
return options;
}

This "start" option does not seem to work as a String. I have tried JSONLiteral but it failed also. I got a Ajax error, something like Communication with the server failed, null.

I also tried in the tml -- t:params="literal:{start: function() {$(this).hide();}}"

But it does not work. In both cases above I tried with arguments: function(event, ui) {}, but it did not work.

How can I declare this function ??

Thanks.
Reply, Re

Re: How to Declare JSONObject function ?

Posted by Dusko Jovanovski <du...@gmail.com>.
options.put("start", new JSONLiteral("function() {$(this).hide();}"));

is the right way to pass the function, but it won't work for AJAX requests
in tapestry 5.4.
Could you please tell us what version of tapestry, tapestry-jquery you are
using? And provide the stacktraces so we can debug further.


On Thu, Mar 20, 2014 at 2:15 PM, john c <jo...@yahoo.com> wrote:

> With <t:jquery.Draggable /> you can specify the JSONObject params like so:
> t:params="params"
> In Java I have code like this (snippet):
>
> public JSONObject getParams() {
> JSONObject options = new JSONObject();
> ......
> ......
> options.put("start", "function() {$(this).hide();}");
> return options;
> }
>
> This "start" option does not seem to work as a String. I have tried
> JSONLiteral but it failed also. I got a Ajax error, something like
> Communication with the server failed, null.
>
> I also tried in the tml -- t:params="literal:{start: function()
> {$(this).hide();}}"
>
> But it does not work. In both cases above I tried with arguments:
> function(event, ui) {}, but it did not work.
>
> How can I declare this function ??
>
> Thanks.
> Reply, Re

Re: How to Declare JSONObject function ?

Posted by john c <jo...@yahoo.com>.
I read the other example and comments, and this is what I changed:

I edited the JSON params like this (removed JSONLiteral):

options.put("start", "aaa"); 


In draganddrop.js I enclosed the function definition like this:

T5.extendInitializers(function() {
function aaa() { 
   alert(); 
} 
});

Then I changed afterRender() like this:

@AfterRender
public void afterRender()
    {
        js.importJavaScriptLibrary(as.getContextAsset("js/draganddrop.js", null); 
        ajaxResponseRenderer.addCallback(new JavaScriptCallback()
        {
            @Override
            public void run(JavaScriptSupport javascriptSupport)
            {
                javascriptSupport.addInitializerCall(InitializationPriority.LATE, "aaa", new JSONObject());
            }
        });
    }

I don't see the Ajax error. But I also don't see the Javascript function being called. I was hoping to see the alert box on start drag.

Any ideas?



On Friday, 21 March 2014 4:19 AM, Boris Horvat <ho...@gmail.com> wrote:
 
Fir me the solution was to use ut without jsonliterl, just put the name of
the fuction without brackets

On 21 Mar 2014 04:31, "john c" <jo...@yahoo.com> wrote:

> First, I am using the latest, Tapestry/Tapestry-JQuery versions: 5.3.7 /
> 3.3.7.
>
> I created draganddrop.js and put it under webapp/js. It has a simple
> function:
>
> function aaa() {
>    alert();
> }
>
> In Java, I added the code like this:
>
> @Inject
> private AssetSource as;
>
> @Inject
> private JavaScriptSupport js;
>
> @AfterRender
> public void afterRender() {
>     js.importJavaScriptLibrary(as.getContextAsset("js/draganddrop.js",
> null);
> }
>
> So the JavaScript should be imported (I successfully imported other js
> scripts this way)....
>
> Then in the same Java class I edited the JSON params to now have:
>
> options.put("start", new JSONLiteral("aaa"));
>
> But I got the same Ajax error, communication with the server failed: null.
>
>
>
> On Thursday, 20 March 2014 11:35 AM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
> I think this (passing a JavaScript parameter from the server side) is not
> recommended anyway. Create this function in some .js file which you
> include in your page or component then pass options.put("start", new
> JSONLiteral("nameOfTheFunction"));
>
>
> On Thu, 20 Mar 2014 10:15:05 -0300, john c <jo...@yahoo.com> wrote:
>
> > With <t:jquery.Draggable /> you can specify the JSONObject params like
> > so: t:params="params"
> > In Java I have code like this (snippet):
> >
> > public JSONObject getParams() {
> > JSONObject options = new JSONObject();
> > ......
> > ......
> > options.put("start", "function() {$(this).hide();}");
> > return options;
> > }
> >
> > This "start" option does not seem to work as a String. I have tried
> > JSONLiteral but it failed also. I got a Ajax error, something like
> > Communication with the server failed, null.
> >
> > I also tried in the tml -- t:params="literal:{start: function()
> > {$(this).hide();}}"
> >
> > But it does not work. In both cases above I tried with arguments:
> > function(event, ui) {}, but it did not work.
> >
> > How can I declare this function ??
> >
> > Thanks.
> > Reply, Re
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org

Re: How to Declare JSONObject function ?

Posted by Boris Horvat <ho...@gmail.com>.
Fir me the solution was to use ut without jsonliterl, just put the name of
the fuction without brackets
On 21 Mar 2014 04:31, "john c" <jo...@yahoo.com> wrote:

> First, I am using the latest, Tapestry/Tapestry-JQuery versions: 5.3.7 /
> 3.3.7.
>
> I created draganddrop.js and put it under webapp/js. It has a simple
> function:
>
> function aaa() {
>    alert();
> }
>
> In Java, I added the code like this:
>
> @Inject
> private AssetSource as;
>
> @Inject
> private JavaScriptSupport js;
>
> @AfterRender
> public void afterRender() {
>     js.importJavaScriptLibrary(as.getContextAsset("js/draganddrop.js",
> null);
> }
>
> So the JavaScript should be imported (I successfully imported other js
> scripts this way)....
>
> Then in the same Java class I edited the JSON params to now have:
>
> options.put("start", new JSONLiteral("aaa"));
>
> But I got the same Ajax error, communication with the server failed: null.
>
>
>
> On Thursday, 20 March 2014 11:35 AM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
> I think this (passing a JavaScript parameter from the server side) is not
> recommended anyway. Create this function in some .js file which you
> include in your page or component then pass options.put("start", new
> JSONLiteral("nameOfTheFunction"));
>
>
> On Thu, 20 Mar 2014 10:15:05 -0300, john c <jo...@yahoo.com> wrote:
>
> > With <t:jquery.Draggable /> you can specify the JSONObject params like
> > so: t:params="params"
> > In Java I have code like this (snippet):
> >
> > public JSONObject getParams() {
> > JSONObject options = new JSONObject();
> > ......
> > ......
> > options.put("start", "function() {$(this).hide();}");
> > return options;
> > }
> >
> > This "start" option does not seem to work as a String. I have tried
> > JSONLiteral but it failed also. I got a Ajax error, something like
> > Communication with the server failed, null.
> >
> > I also tried in the tml -- t:params="literal:{start: function()
> > {$(this).hide();}}"
> >
> > But it does not work. In both cases above I tried with arguments:
> > function(event, ui) {}, but it did not work.
> >
> > How can I declare this function ??
> >
> > Thanks.
> > Reply, Re
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org

Re: How to Declare JSONObject function ?

Posted by Dmitry Gusev <dm...@gmail.com>.
We had similar discussion recently:

http://apache-tapestry-mailing-list-archives.1045711.n5.nabble.com/How-to-pass-a-javascript-function-in-tapestry-mixin-td5725837.html

On Friday, March 21, 2014, john c <jo...@yahoo.com> wrote:

> First, I am using the latest, Tapestry/Tapestry-JQuery versions: 5.3.7 /
> 3.3.7.
>
> I created draganddrop.js and put it under webapp/js. It has a simple
> function:
>
> function aaa() {
>    alert();
> }
>
> In Java, I added the code like this:
>
> @Inject
> private AssetSource as;
>
> @Inject
> private JavaScriptSupport js;
>
> @AfterRender
> public void afterRender() {
>     js.importJavaScriptLibrary(as.getContextAsset("js/draganddrop.js",
> null);
> }
>
> So the JavaScript should be imported (I successfully imported other js
> scripts this way)....
>
> Then in the same Java class I edited the JSON params to now have:
>
> options.put("start", new JSONLiteral("aaa"));
>
> But I got the same Ajax error, communication with the server failed: null.
>
>
>
> On Thursday, 20 March 2014 11:35 AM, Thiago H de Paula Figueiredo <
> thiagohp@gmail.com <javascript:;>> wrote:
>
> I think this (passing a JavaScript parameter from the server side) is not
> recommended anyway. Create this function in some .js file which you
> include in your page or component then pass options.put("start", new
> JSONLiteral("nameOfTheFunction"));
>
>
> On Thu, 20 Mar 2014 10:15:05 -0300, john c <john998800@yahoo.com<javascript:;>>
> wrote:
>
> > With <t:jquery.Draggable /> you can specify the JSONObject params like
> > so: t:params="params"
> > In Java I have code like this (snippet):
> >
> > public JSONObject getParams() {
> > JSONObject options = new JSONObject();
> > ......
> > ......
> > options.put("start", "function() {$(this).hide();}");
> > return options;
> > }
> >
> > This "start" option does not seem to work as a String. I have tried
> > JSONLiteral but it failed also. I got a Ajax error, something like
> > Communication with the server failed, null.
> >
> > I also tried in the tml -- t:params="literal:{start: function()
> > {$(this).hide();}}"
> >
> > But it does not work. In both cases above I tried with arguments:
> > function(event, ui) {}, but it did not work.
> >
> > How can I declare this function ??
> >
> > Thanks.
> > Reply, Re
>
>
> --
> Thiago H. de Paula Figueiredo
> Tapestry, Java and Hibernate consultant and developer
> http://machina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org<javascript:;>
> For additional commands, e-mail: users-help@tapestry.apache.org<javascript:;>



-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Re: How to Declare JSONObject function ?

Posted by john c <jo...@yahoo.com>.
First, I am using the latest, Tapestry/Tapestry-JQuery versions: 5.3.7 / 3.3.7.

I created draganddrop.js and put it under webapp/js. It has a simple function:

function aaa() {
   alert();
}

In Java, I added the code like this:

@Inject
private AssetSource as;

@Inject
private JavaScriptSupport js;

@AfterRender
public void afterRender() {
    js.importJavaScriptLibrary(as.getContextAsset("js/draganddrop.js", null);
}

So the JavaScript should be imported (I successfully imported other js scripts this way)....

Then in the same Java class I edited the JSON params to now have:

options.put("start", new JSONLiteral("aaa"));

But I got the same Ajax error, communication with the server failed: null.



On Thursday, 20 March 2014 11:35 AM, Thiago H de Paula Figueiredo <th...@gmail.com> wrote:
 
I think this (passing a JavaScript parameter from the server side) is not  
recommended anyway. Create this function in some .js file which you  
include in your page or component then pass options.put("start", new  
JSONLiteral("nameOfTheFunction"));


On Thu, 20 Mar 2014 10:15:05 -0300, john c <jo...@yahoo.com> wrote:

> With <t:jquery.Draggable /> you can specify the JSONObject params like  
> so: t:params="params"
> In Java I have code like this (snippet):
>
> public JSONObject getParams() {
> JSONObject options = new JSONObject();
> ......
> ......
> options.put("start", "function() {$(this).hide();}");
> return options;
> }
>
> This "start" option does not seem to work as a String. I have tried  
> JSONLiteral but it failed also. I got a Ajax error, something like  
> Communication with the server failed, null.
>
> I also tried in the tml -- t:params="literal:{start: function()  
> {$(this).hide();}}"
>
> But it does not work. In both cases above I tried with arguments:  
> function(event, ui) {}, but it did not work.
>
> How can I declare this function ??
>
> Thanks.
> Reply, Re


-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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

Re: How to Declare JSONObject function ?

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
I think this (passing a JavaScript parameter from the server side) is not  
recommended anyway. Create this function in some .js file which you  
include in your page or component then pass options.put("start", new  
JSONLiteral("nameOfTheFunction"));

On Thu, 20 Mar 2014 10:15:05 -0300, john c <jo...@yahoo.com> wrote:

> With <t:jquery.Draggable /> you can specify the JSONObject params like  
> so: t:params="params"
> In Java I have code like this (snippet):
>
> public JSONObject getParams() {
> JSONObject options = new JSONObject();
> ......
> ......
> options.put("start", "function() {$(this).hide();}");
> return options;
> }
>
> This "start" option does not seem to work as a String. I have tried  
> JSONLiteral but it failed also. I got a Ajax error, something like  
> Communication with the server failed, null.
>
> I also tried in the tml -- t:params="literal:{start: function()  
> {$(this).hide();}}"
>
> But it does not work. In both cases above I tried with arguments:  
> function(event, ui) {}, but it did not work.
>
> How can I declare this function ??
>
> Thanks.
> Reply, Re


-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

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