Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

integrate DWR with struts

 
Orod Semsarzadeh
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Uma Mahi
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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>
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • 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 ]
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • 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
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic