• 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

integrate DWR with struts

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I want to integrate DWR with struts. I set <create creator="struts" .../> in dwr.xml, but unfortunately, I dont get any js.

Anybody can help me to use DWR and struts together? Is there anybody done it in a project?

please give me your sugegstions or experiences.

I look forward to hearing from you.

Yours faithfully,

Orod Semsarzadeh
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<!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="">
<param name="class" value=""/>
</create>
</allow>
</dwr>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've done a project that integrated Struts and DWR.

I did not use the Struts creator, and don't really see a need to do so. The only thing the Struts creator does is give you access to your ActionForm bean. If something is in my ActionForm bean, I've already accessed it when I first displayed the page. When I make an AJAX call, I generally want things that are not in my ActionForm bean.

As Uma suggests, I just use the "new" creator and provide a class that has a method I want to call.

Here's an example:


Then in your JSP:
<script src='dwr/interface/WidgetDAO.js'></script>
<script src='dwr/engine.js'></script>
<script src='dwr/util.js'></script>
<script>
function doIt() {
WidgetDAO.getWidgets(....);
...
)
</script>

Note: There is no actual physical file dwr/interface/WidgetDAO.js. this is a virtual reference that is resolved at run-time, just as myAction.do is resolved at runtime. So, don't panic if you can't find this file. It will be there at run-time.
[ July 04, 2006: Message edited by: Merrill Higginson ]
 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I want to be able to do something similar to what you did. I am calling a method in my delegate class which looks like this

public String MyDelegate ( MyObject object ){

//do my stuff here

return someString ;
}

this method gets called from my jsp but object(type MyObject) is of course null. I can easily get this object in struts action class using
formbean.get ( "object" ) ;

how do i get this object since i m using DWR.

Thanks
Imad
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's important to understand that when making an AJAX call, the HTML Form is not submitted. This means that the normal process Struts goes through of creating an ActionForm based on the contents of the submitted form is not done by DWR.

What I'd recommend is that you create a JavaScript object that has the same properties as the object you want to pass to your method. Then just pass the object in as a parameter when you make the DWR JavaScript call. DWR will automatically create a Java object of the correct type and populate its properties based on the JavaScript object properties.

For example: Suppose your object has id, name, and amount properties.

You would have an entry like this in your dwr.xml file:

Your JavaScript code would look something like this:

[ December 04, 2006: Message edited by: Merrill Higginson ]
 
There is no greater crime than stealing somebody's best friend. I miss you tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic