aspose file tools*
The moose likes Struts and the fly likes integrate DWR with struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "integrate DWR with struts" Watch "integrate DWR with struts" New topic
Author

integrate DWR with struts

Orod Semsarzadeh
Greenhorn

Joined: Jul 03, 2006
Posts: 1
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

Joined: Jan 11, 2006
Posts: 34
<!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>


Umaa Mahi<br />--SCJP1.4
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
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 ]

Merrill
Consultant, Sima Solutions
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
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

Joined: Feb 15, 2005
Posts: 4864
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: integrate DWR with struts