You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Peer Brink <pe...@gmail.com> on 2008/08/05 11:40:37 UTC

Transmitting a javascript-value to the server using JSON

Hello,

I try to transmit the users/browsers timezone-offset to the server.
The timeZone-offset can easily be retrieved by

<script type="text/javascript">
var offset = new Date().getTimezoneOffset();
</script>

But how can it be transmitted? Could this be done using a JSONObject
by adding "Object.toJSON(offset);"?

I found quite some conversations in the mailing-list about
JSON-communication but they are all about transmitting data in the
other direction (server to client).

Where would the code go in the html-source and what java-code is
needed to receive the value on the server-side?

Or is there a complete other way to get this value?

Sorry for this rookie-question. But I am not too familiar with
java-script and JSON.

Thanks for any help,
Peer.

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


Re: Transmitting a javascript-value to the server using JSON

Posted by Kalle Korhonen <ka...@gmail.com>.
Well well, looks like Chenillekit's OnEvent is pretty close to what I want.
I think you still got to make your Javascript thing a component though, but
otherwise it functions similarly to T4's EventListener.

Kalle


On Sat, Jan 17, 2009 at 9:46 AM, Kalle Korhonen
<ka...@gmail.com>wrote:

> On Sat, Jan 17, 2009 at 6:55 AM, Thiago H. de Paula Figueiredo <
> thiagohp@gmail.com> wrote:
>
>> Em Sat, 17 Jan 2009 01:56:08 -0300, Kalle Korhonen <
>> kalle.o.korhonen@gmail.com> escreveu:
>>
>>> ActionLink with zone and @OnEvent on the server, but what I loved about
>>> T4's EventListener was that you could hook an arbitrary Javascript call to a
>>> server side operation with one annotation. I have a case where I'd like
>>> to do communicate in the background from plain Javascript rather than "click
>>> a link".
>>>
>> What's the closest equivalent of T4's EventListener in T5? You can do
>>
>> Have you tried to generate the link though LinkFactory and use it in your
>> Javascript code?
>>
>
> Yes, that'd be a bit better though still not quite the same as the
> EventListener. But at least I can stick that link directly into my
> Javascript that way I think, thanks.
>
> Kalle
>

Re: Transmitting a javascript-value to the server using JSON

Posted by Kalle Korhonen <ka...@gmail.com>.
On Sat, Jan 17, 2009 at 6:55 AM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> Em Sat, 17 Jan 2009 01:56:08 -0300, Kalle Korhonen <
> kalle.o.korhonen@gmail.com> escreveu:
>>
>> ActionLink with zone and @OnEvent on the server, but what I loved about
>> T4's EventListener was that you could hook an arbitrary Javascript call to a
>> server side operation with one annotation. I have a case where I'd like to
>> do communicate in the background from plain Javascript rather than "click a
>> link".
>>
> What's the closest equivalent of T4's EventListener in T5? You can do
>
> Have you tried to generate the link though LinkFactory and use it in your
> Javascript code?
>

Yes, that'd be a bit better though still not quite the same as the
EventListener. But at least I can stick that link directly into my
Javascript that way I think, thanks.

Kalle

Re: Transmitting a javascript-value to the server using JSON

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Sat, 17 Jan 2009 01:56:08 -0300, Kalle Korhonen  
<ka...@gmail.com> escreveu:

> What's the closest equivalent of T4's EventListener in T5? You can do
> ActionLink with zone and @OnEvent on the server, but what I loved about  
> T4's EventListener was that you could hook an arbitrary Javascript call  
> to a
> server side operation with one annotation. I have a case where I'd like  
> to do communicate in the background from plain Javascript rather than  
> "click a link".

Have you tried to generate the link though LinkFactory and use it in your  
Javascript code?

-- 
Thiago H. de Paula Figueiredo
Independent Java consultant, developer, and instructor
http://www.arsmachina.com.br/thiago

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


Re: Transmitting a javascript-value to the server using JSON

Posted by Kalle Korhonen <ka...@gmail.com>.
What's the closest equivalent of T4's EventListener in T5? You can do
ActionLink with zone and @OnEvent on the server, but what I loved about T4's
EventListener was that you could hook an arbitrary Javascript call to a
server side operation with one annotation. I have a case where I'd like to
do communicate in the background from plain Javascript rather than "click a
link".

Kalle


On Tue, Aug 5, 2008 at 3:30 PM, Toby Hobson <to...@googlemail.com>wrote:

> Does anyone know if something similar is available (or planned) for T5?
>
> Toby
>
> 2008/8/5 Thiago Henrique de Carvalho <ka...@gmail.com>
>
> > Hi,
> >
> > Take a look at @EventListener annotation. Docs show example of
> transmiting
> > JSON from page to Tapestry.
> >
> > Thiago
> >
> > -----Mensagem original-----
> > De: Peer Brink [mailto:peerbrink@gmail.com]
> > Enviada em: terça-feira, 5 de agosto de 2008 06:41
> > Para: users@tapestry.apache.org
> > Assunto: Transmitting a javascript-value to the server using JSON
> >
> > Hello,
> >
> > I try to transmit the users/browsers timezone-offset to the server.
> > The timeZone-offset can easily be retrieved by
> >
> > <script type="text/javascript">
> > var offset = new Date().getTimezoneOffset();
> > </script>
> >
> > But how can it be transmitted? Could this be done using a JSONObject
> > by adding "Object.toJSON(offset);"?
> >
> > I found quite some conversations in the mailing-list about
> > JSON-communication but they are all about transmitting data in the
> > other direction (server to client).
> >
> > Where would the code go in the html-source and what java-code is
> > needed to receive the value on the server-side?
> >
> > Or is there a complete other way to get this value?
> >
> > Sorry for this rookie-question. But I am not too familiar with
> > java-script and JSON.
> >
> > Thanks for any help,
> > Peer.
> >
> > ---------------------------------------------------------------------
> > 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: Transmitting a javascript-value to the server using JSON

Posted by Peer Brink <pe...@gmail.com>.
Dear Toby,

thanks for your comments on this. But I decided to use a hidden form
field (from t5components) and fill it with the offset-value using
javascript. It seems to me that this is the simpler solution.

I described the details in another thread (subject: "Getting users
timezone-offset (javascript)".

Nevertheless I would very much appreciate a simple T5-support for
transfering values from the client to the server.

Regards,
Peer.

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


Re: Transmitting a javascript-value to the server using JSON

Posted by Toby Hobson <to...@googlemail.com>.
Does anyone know if something similar is available (or planned) for T5?

Toby

2008/8/5 Thiago Henrique de Carvalho <ka...@gmail.com>

> Hi,
>
> Take a look at @EventListener annotation. Docs show example of transmiting
> JSON from page to Tapestry.
>
> Thiago
>
> -----Mensagem original-----
> De: Peer Brink [mailto:peerbrink@gmail.com]
> Enviada em: terça-feira, 5 de agosto de 2008 06:41
> Para: users@tapestry.apache.org
> Assunto: Transmitting a javascript-value to the server using JSON
>
> Hello,
>
> I try to transmit the users/browsers timezone-offset to the server.
> The timeZone-offset can easily be retrieved by
>
> <script type="text/javascript">
> var offset = new Date().getTimezoneOffset();
> </script>
>
> But how can it be transmitted? Could this be done using a JSONObject
> by adding "Object.toJSON(offset);"?
>
> I found quite some conversations in the mailing-list about
> JSON-communication but they are all about transmitting data in the
> other direction (server to client).
>
> Where would the code go in the html-source and what java-code is
> needed to receive the value on the server-side?
>
> Or is there a complete other way to get this value?
>
> Sorry for this rookie-question. But I am not too familiar with
> java-script and JSON.
>
> Thanks for any help,
> Peer.
>
> ---------------------------------------------------------------------
> 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
>
>

RES: Transmitting a javascript-value to the server using JSON

Posted by Thiago Henrique de Carvalho <ka...@gmail.com>.
Hi,

Take a look at @EventListener annotation. Docs show example of transmiting
JSON from page to Tapestry.

Thiago

-----Mensagem original-----
De: Peer Brink [mailto:peerbrink@gmail.com] 
Enviada em: terça-feira, 5 de agosto de 2008 06:41
Para: users@tapestry.apache.org
Assunto: Transmitting a javascript-value to the server using JSON

Hello,

I try to transmit the users/browsers timezone-offset to the server.
The timeZone-offset can easily be retrieved by

<script type="text/javascript">
var offset = new Date().getTimezoneOffset();
</script>

But how can it be transmitted? Could this be done using a JSONObject
by adding "Object.toJSON(offset);"?

I found quite some conversations in the mailing-list about
JSON-communication but they are all about transmitting data in the
other direction (server to client).

Where would the code go in the html-source and what java-code is
needed to receive the value on the server-side?

Or is there a complete other way to get this value?

Sorry for this rookie-question. But I am not too familiar with
java-script and JSON.

Thanks for any help,
Peer.

---------------------------------------------------------------------
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: Transmitting a javascript-value to the server using JSON

Posted by Toby Hobson <to...@googlemail.com>.
Hello Peer,

Sure it can be done ... have a look at JSON.stringify() at
http://www.json.org/js.html, this will turn the Javascript object into JSON
text.

On the server-side you need to use JSONTokener and JSONObject see
http://www.json.org/java/index.html to convert back to a Java object

If you need more help let me know

Regards

Toby

2008/8/5 Peer Brink <pe...@gmail.com>

> Hello,
>
> I try to transmit the users/browsers timezone-offset to the server.
> The timeZone-offset can easily be retrieved by
>
> <script type="text/javascript">
> var offset = new Date().getTimezoneOffset();
> </script>
>
> But how can it be transmitted? Could this be done using a JSONObject
> by adding "Object.toJSON(offset);"?
>
> I found quite some conversations in the mailing-list about
> JSON-communication but they are all about transmitting data in the
> other direction (server to client).
>
> Where would the code go in the html-source and what java-code is
> needed to receive the value on the server-side?
>
> Or is there a complete other way to get this value?
>
> Sorry for this rookie-question. But I am not too familiar with
> java-script and JSON.
>
> Thanks for any help,
> Peer.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>