convrtor in AJAX in DWR....what is this ?

G

gk

hi,

i dont understand what is the job of converter in DWR AJAX.

can anybody please help me


http://getahead.ltd.uk/dwr/server/dwrxml/converters

converting my java classes to what ?

why does it convert ?


for example : i have a dwr.xml where

dwr.xml
========

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">

<dwr>
<allow>
<create creator="new" javascript="Chat">
<param name="class" value="[your.package].Chat"/>
</create>
<convert converter="bean" match="[your.package].Message"/>
</allow>
</dwr>


look at this steps <convert converter="bean"
match="[your.package].Message"/>

it is converting a java class named "Message" to "bean"......why ?
whats the "bean" means now ?


very confusing.

please help ....explain
 
G

gk

Haider said:
Hi,
This converter works as an adapter between the old java objects and the
Javascript.

OK.

so, what this code means
<convert converter="bean" match="[your.package].Message"/>


does it convert the Message class into a javascript object named
"bean".....or whats going on here ?

please explain this stuff.

how do i use this "bean" then ? this is not a java object ? i can not
use "." operator to access the class methods......so, whats the worth
of it ?
 
S

Steve Sobol

gk said:
so, what this code means
<convert converter="bean" match="[your.package].Message"/>


does it convert the Message class into a javascript object named
"bean".....or whats going on here ?

"bean" is the type of converter. It's used to expose a class that you create.
how do i use this "bean" then ? this is not a java object ? i can not
use "." operator to access the class methods......so, whats the worth
of it ?

Have you looked at some of the samples? DWR's pretty easy to use. I've
started using it for the first time, on a project I'm working on, and
created a simple Java class and was able to expose it via Javascript using
DWR without any major hassles.
 
G

gk

Steve said:
gk said:
so, what this code means
<convert converter="bean" match="[your.package].Message"/>


does it convert the Message class into a javascript object named
"bean".....or whats going on here ?

"bean" is the type of converter. It's used to expose a class that you create.
how do i use this "bean" then ? this is not a java object ? i can not
use "." operator to access the class methods......so, whats the worth
of it ?

Have you looked at some of the samples? DWR's pretty easy to use. I've
started using it for the first time, on a project I'm working on, and
created a simple Java class and was able to expose it via Javascript using
DWR without any major hassles.


yes. i am reading the documentation.

and they are using "convertor" thingie which i dont understand.

do you use "convertor" in your dwr.xml file ?





For example :

<convert converter="bean" match="[your.package].Message"/>

what it does basically ?



QUESTION 1 :

does it convert the "[your.package].Message" class into a javascript
variable ? whats the name of that variable ? is that name "bean" ?

does it mean a javascript variable whose name is "bean" is available
in the client side ....and this variable "bean" represents the POJO.

is it like this ?






QUESTION 2:


the docs says, the convertor converts the POJO into javascript object
..

How do you access that object in javascript now ? because, in java we
acces a method

objectname.MethodName();

if that POJO is now converted into javascript object , how do i access
methods now ?



QUESTION 3:

do you use <convertor tag in your dwr.xml ?
 
S

Steve Sobol

gk said:
no body there ...

Sorry, it was late and I had to sleep. Try being patient next time you ask
a question on Usenet - you won't necessarily get an immediate answer.
 
S

Steve Sobol

gk said:
yes. i am reading the documentation.

FYI, http://getahead.ltd.uk/dwr/documentation is where I am, not the page at
dwr.dev.java.net - the uk address is the main project website.

http://getahead.ltd.uk/dwr/server/dwrxml talks about web.xml

http://getahead.ltd.uk/dwr/server/dwrxml/creators is the first thing you
need to look at. I have both a creator and a converter:

<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="Demo">
<param name="class" value="com.yourwebmail.Addit"/>
</create>
<convert converter="bean" match="com.yourwebmail.Addit"/>
</allow>
</dwr>

I don't use BeanShell or Spring, so I'm creating the bean using the
creator="new" attribute in the create tag. It's exposed to my Javascript as
an object named Demo.

The creator can specify which methods are exposed to Javascript.

Then the converter tag uses the Bean converter,
http://getahead.ltd.uk/dwr/server/dwrxml/converters/bean

to actually convert my JavaBean into something usable by Javascript.

My Addit class is

package com.yourwebmail;

public class Addit {
public int add3(int i) {
return(i+3);
}
}

and I call it this way:

<script type="text/javascript"
src="http://YOUR_HOSTNAME_HERE/dwr/interface/Remote.js"> </script>
<script type="text/javascript"
src="http://YOUR_HOSTNAME_HERE/dwr/engine.js"> </script>
<script>
function handleGetData(str)
{
alert(str);
}

Demo.add3(42, handleGetData);
</script>

This calls my class's add3 method, passes in 42 and will pop up an alert box
displaying 45.

Hopefully this is clearer to you having seen all of the pieces in one place
but again, I strongly suggest that you look at the samples.

QUESTION 1 :

does it convert the "[your.package].Message" class into a javascript
variable ? whats the name of that variable ? is that name "bean" ?

The Javascript variable is whatever you specify in the javascript attribute
of the said:
QUESTION 2:


the docs says, the convertor converts the POJO into javascript object

How do you access that object in javascript now ? because, in java we
acces a method

See above.
if that POJO is now converted into javascript object , how do i access
methods now ?

Don't think "converted" - think "exposed to JavaScript". On the backend, DWR
will still make a method call to your POJO.

QUESTION 3:
do you use <convertor tag in your dwr.xml ?

Yes.
 
G

gk

you have this code

public class Addit {
public int add3(int i) {
return(i+3);
}


Demo.add3(42, handleGetData);





Question 1:
===========


will you please tell


Demo.add3(42, handleGetData);

AND

Demo.add3(handleGetData,42);


are same?

//Note the order.




















Steve said:
gk said:
yes. i am reading the documentation.

FYI, http://getahead.ltd.uk/dwr/documentation is where I am, not the page at
dwr.dev.java.net - the uk address is the main project website.

http://getahead.ltd.uk/dwr/server/dwrxml talks about web.xml

http://getahead.ltd.uk/dwr/server/dwrxml/creators is the first thing you
need to look at. I have both a creator and a converter:

<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="Demo">
<param name="class" value="com.yourwebmail.Addit"/>
</create>
<convert converter="bean" match="com.yourwebmail.Addit"/>
</allow>
</dwr>

I don't use BeanShell or Spring, so I'm creating the bean using the
creator="new" attribute in the create tag. It's exposed to my Javascript as
an object named Demo.

The creator can specify which methods are exposed to Javascript.

Then the converter tag uses the Bean converter,
http://getahead.ltd.uk/dwr/server/dwrxml/converters/bean

to actually convert my JavaBean into something usable by Javascript.

My Addit class is

package com.yourwebmail;

public class Addit {
public int add3(int i) {
return(i+3);
}
}

and I call it this way:

<script type="text/javascript"
src="http://YOUR_HOSTNAME_HERE/dwr/interface/Remote.js"> </script>
<script type="text/javascript"
src="http://YOUR_HOSTNAME_HERE/dwr/engine.js"> </script>
<script>
function handleGetData(str)
{
alert(str);
}

Demo.add3(42, handleGetData);
</script>

This calls my class's add3 method, passes in 42 and will pop up an alert box
displaying 45.

Hopefully this is clearer to you having seen all of the pieces in one place
but again, I strongly suggest that you look at the samples.

QUESTION 1 :

does it convert the "[your.package].Message" class into a javascript
variable ? whats the name of that variable ? is that name "bean" ?

The Javascript variable is whatever you specify in the javascript attribute
of the said:
QUESTION 2:


the docs says, the convertor converts the POJO into javascript object

How do you access that object in javascript now ? because, in java we
acces a method

See above.
if that POJO is now converted into javascript object , how do i access
methods now ?

Don't think "converted" - think "exposed to JavaScript". On the backend, DWR
will still make a method call to your POJO.

QUESTION 3:
do you use <convertor tag in your dwr.xml ?

Yes.

--
Steve Sobol, Professional Geek 888-480-4638 PGP: 0xE3AE35ED
Company website: http://JustThe.net/
Personal blog, resume, portfolio: http://SteveSobol.com/
E: (e-mail address removed) Snail: 22674 Motnocab Road, Apple Valley, CA 92307
 
S

Steve Sobol

gk said:
Demo.add3(42, handleGetData);

AND

Demo.add3(handleGetData,42);


are same?

Ummmm, if I remember correctly, you can put the callback function before the
arguments or after, but it's suggested that the callback function be listed
last. But you'll want to check the DWR website to be sure.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top