• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Reimplementing parts of my app with DWR

 
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
I'm trying to reimplement parts of my web app using DWR.
ShoppingCart class has the following method :
public void addToCart(BookItem bookItem)
Here is a snippet from AddToCartAction :

My problem is how to code the same previous code in JavaScript ?
No way, right ?
I have to create a new method with the following signature :
public void addToCart(String isbn)
Right ?
[ January 24, 2007: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your question is vague beyond comprehension.

Are you talking about server-side Java methods or Javascript?

Generally DWR creates the Javascript functions that serve as the proxy stub for the corresponding server-side Java methods.
 
Bear Bibeault
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also updated your title to be more accurate.
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, I mean :
Inside my Struts Action class, I'm able to get the Book from the session object and then create a BookItem.
Check the signature please :
public void addToCart(BookItem bookItem)
Now, if I want to use DWR, my JavaScript code should call the previous method but I don't know how ?
Yes, DWR will expose Cart object so I can call addToCart(BookItem) but how to access Book instance (from JavaScript) which it is stored in session scoped object and then creates a BookItem instance ?
Sorry but Am I clear ?
[ January 24, 2007: Message edited by: John Todd ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really think you need to not jump into it, but actually sit down an work with the examples.

http://code.google.com/webtoolkit/documentation/examples/

It is like you just jumped into the middle of the ocean and you do not know how to swim.

Eric
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eric but may I ask you why you referenced to GWT ? (I'm using DWR).
Sorry if I missed something
 
Bear Bibeault
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Eric may have pointed you to the wrong tutorial, but his point is valid.

With DWR, you do not define the Javascript proxy functions, DWR does that for you.

You really need to get more familiar with how DWR works.

If you can't find an online tutorial, you can obtain the Manning Ajax in Practice book in which I discuss DWR in chapter 4. The book is unpublished as of yet but can be obtained via MEAP (Manning Early Acces Program).
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, you absolutley have the right to kick my *** but ...
I have been reading some tutorials about DWR (IBM dW, dev2Dev, java.net)

DWR is an engine that exposes methods of server-side Java objects to JavaScript code.


for each exposed class, DWR dynamically generates JavaScript to include in your Web page. The generated JavaScript contains stub functions that represent the corresponding methods on the Java class and also performs XMLHttpRequests behind the scenes.


With DWR, you do not define the Javascript proxy functions, DWR does that for you.


When I click on add to cart button, a JavaScript function should be executed, something like :

Sorry, I feel I'm repeating myself but I'm unable to understand this.
Well, kick me !
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you tell us what steps you have taken to get to this point.

What configuration have you done (web.xml, dwr.xml)?

Do you see your class on the dwr test page? The test page shows the javascript to add to your page, did you do that?

Did you work through these?

http://getahead.ltd.uk/dwr/getstarted
http://getahead.ltd.uk/dwr/browser/intro
[ January 28, 2007: Message edited by: Carol Enderlin ]
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I have a Struts action , AddToCartAction :

I want to reimplement this using DWR, I don't want the previous action to be executed.
When the user clicks on 'Add To Cart' button at details.jsp page, addToCartHandler( ) JavaScript function should run.
I exposed my cart object under name Cart in dwr.xml :

My whole problem is how to get the Book instance from the session object inside my JavaScript
code (Shopping.js) ?
After reading DWR docs (http://getahead.ltd.uk/dwr/server/javaapi), I got this :
Creat a class :

Then inside my JavaScript :
Service.addTocart( );
So ??
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lots of questions or actually question marks. Have you tried something (I mean hooking up your javascript to actually call your class with the dwr-generated javascript)? What are you stuck on?

Can you do something simpler with DWR? I don't think you answered any of my questions. Oh wait, you said you put your cart object in dwr.xml, but the code you showed is for a service class. My turn for a question mark...?

Your javascript doesn't have access to the session, but your class does.
[ January 28, 2007: Message edited by: Carol Enderlin ]
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This page describes two ways to get servlet objects (e.g. session) in DWR-exposed methods: Accessing Servlet Objects

1. Use WebContextFactory to get WebContext. From WebContext you can get request, etc.

2. Add the object of interest to the signature "and upon a call of the method it will fill it in automagically."
 
Hussein Baghdadi
clojure forum advocate
Posts: 3479
Mac Objective C Clojure
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Have you tried something (I mean hooking up your javascript to actually call your class with the dwr-generated javascript)? What are you stuck on?


Yes, using http://localhost:8080/store/dwr/
Sure, I can create a JavaScript version of BookItem with JSON but this is so helpful since the real application will get its BookItem from the session.


Oh wait, you said you put your cart object in dwr.xml, but the code you showed is for a service class.


Sorry, this is my fault
Service class is a walk around way to my problem and has nothing to do with the original post (a solution).


Add the object of interest to the signature "and upon a call of the method it will fill it in automagically


Please correct me if I'm wrong but we can't use any object, just the standard HTTP servlet objects.

[ January 30, 2007: Message edited by: John Todd ]
[ January 30, 2007: Message edited by: John Todd ]
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Todd:

Please correct me if I'm wrong but we can't use any object, just the standard HTTP servlet objects.



You can pass objects in. You have to add a converter to dwr.xml for the classes, for example javabean converter, just like you would if you were returning objects from a dwr call:

<convert converter="bean" match="com.foo.MyClass"/>

DWR has utility javascript to help populate the objects from form data.

For tutorial with example see Using DWR (Direct Web Remoting) for Building AJAX Applications

Beyond the object question, do you still have issues or questions?
[ January 30, 2007: Message edited by: Carol Enderlin ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic