Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
gk - 17 Jan 2006 07:23 GMT
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
Haider Albassam - 17 Jan 2006 13:36 GMT
Hi,
This converter works as an adapter between the old java objects and the
Javascript.
For more info.:
http://www.ddj.com/documents/s=9948/ddj0602c/0602c.html

-Haider
gk - 18 Jan 2006 04:41 GMT
> 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 ?
Steve Sobol - 18 Jan 2006 05:13 GMT
> 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.

Signature

Steve Sobol, Professional Geek   888-480-4638   PGP: 0xE3AE35ED
Company website: http://JustThe.net/
Personal blog, resume, portfolio: http://SteveSobol.com/
E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307

gk - 18 Jan 2006 06:35 GMT
> > so, what this code  means
> > <convert converter="bean" match="[your.package].Message"/>
[quoted text clipped - 12 lines]
> 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  ?

> Steve Sobol, Professional Geek   888-480-4638   PGP: 0xE3AE35ED
> Company website: http://JustThe.net/
> Personal blog, resume, portfolio: http://SteveSobol.com/
> E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307
gk - 18 Jan 2006 12:45 GMT
no body there ...
Steve Sobol - 18 Jan 2006 14:38 GMT
> 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.

Signature

Steve Sobol, Professional Geek   888-480-4638   PGP: 0xE3AE35ED
Company website: http://JustThe.net/
Personal blog, resume, portfolio: http://SteveSobol.com/
E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307

Steve Sobol - 18 Jan 2006 14:47 GMT
>>> use "." operator to access the class methods......so,  whats the worth
>>> of it ?
[quoted text clipped - 4 lines]
>
> 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 <creator> tag. Mine is "Demo"

> 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.

Signature

Steve Sobol, Professional Geek   888-480-4638   PGP: 0xE3AE35ED
Company website: http://JustThe.net/
Personal blog, resume, portfolio: http://SteveSobol.com/
E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307

gk - 19 Jan 2006 05:21 GMT
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.

> >>> use "." operator to access the class methods......so,  whats the worth
> >>> of it ?
[quoted text clipped - 100 lines]
> Personal blog, resume, portfolio: http://SteveSobol.com/
> E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307
Steve Sobol - 20 Jan 2006 05:39 GMT
> Demo.add3(42, handleGetData);
>
[quoted text clipped - 3 lines]
>
> 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.

Signature

Steve Sobol, Professional Geek   888-480-4638   PGP: 0xE3AE35ED
Company website: http://JustThe.net/
Personal blog, resume, portfolio: http://SteveSobol.com/
E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307

gk - 20 Jan 2006 06:41 GMT
thank you very much.

you helped me a lot.

great man.

regards

> > Demo.add3(42, handleGetData);
> >
[quoted text clipped - 13 lines]
> Personal blog, resume, portfolio: http://SteveSobol.com/
> E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307
Steve Sobol - 20 Jan 2006 07:02 GMT
> thank you very much.

Don't mention it. I just happen to be doing my first DWR project, and I've
completed a couple successful tests, and I'm happy to be able to help.

For the rest of you that aren't familiar with Direct Web Remoting - it's an
interesting (and, I believe, quite useful) project.

http://getahead.ltd.uk/dwr

http://dwr.dev.java.net/

Signature

Steve Sobol, Professional Geek   888-480-4638   PGP: 0xE3AE35ED
Company website: http://JustThe.net/
Personal blog, resume, portfolio: http://SteveSobol.com/
E: sjsobol@JustThe.net Snail: 22674 Motnocab Road, Apple Valley, CA 92307



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.