3

How exactly is Javascript code generated in Direct Web Remoting (DWR)? I have gone through the official site http://directwebremoting.org as well as other sources (http://directwebremoting.org/dwr/introduction/scripting-dwr.html) and understand there are 3 JS files.

But my question is; how is the JS generated and is it possible to make changes/customize any of the functions? If yes, how?

Thank you.

Vik David
  • 3,640
  • 4
  • 21
  • 29
copenndthagen
  • 49,230
  • 102
  • 290
  • 442

1 Answers1

2

You can examine these files for better understanding, but they're meant to behave as plumbing. It would be better for maintainability if you kept your custom code separate.

The 'engine.js' and 'util.js' files are inside the DWR jar, in the folder: org/directwebremoting. The engine.js file contains some ${...} variables that are replaced by the servlet before the file is sent to the browser. The util.js file contains no such variables.

The interface files are more complicated. I have never needed to make changes or customize these (which is good design on DWRs part actually). My guess is that the interface based js file(s) are generated by what you configure in dwr.xml and DWR's use of the reflection API to read the Java helper class and generate a Javascript-stub to map to it. You can view these file(s) by pasting the URL from your <script src=".../dwr/interface/filename.js"> into a different browser tab.

Vik David
  • 3,640
  • 4
  • 21
  • 29
  • I did not gquite get the statement "The 'engine.js' and 'util.js' files are inside the DWR jar, in the folder".. For the JS files referred in the JSP, do they have any physical existence OR are they just virtual...under myapp/dwr/.. – copenndthagen Apr 19 '11 at 13:22
  • myapp/dwr maps to the DWR servlet. The servlet has to get the files from somewhere (they're not small) so yes they have a physical existance. Find your DWR .jar file under WEB-INF/lib, and expand it using: jar xvf DWR*.jar. You will see a folder org/directwebremoting. The engine.js and util.js files are in that folder. – Vik David Apr 19 '11 at 13:51
  • Thanks a lot for the info..But just a quick question..My script path says But I cannot find a folder named "myapp" anywhere..I did a global search for the same..Am I not understanding something correctly? – copenndthagen Apr 19 '11 at 17:08
  • Scripts paths that begin with [appname]/dwr/interface are auto-generated, so that's why you can't find it. (Refer to 3rd paragraph of my answer :-) – Vik David Apr 19 '11 at 17:55
  • ok..So I am able to locate 2 js; engine.js and util.js...For the 3rd one MyScript.js..are you saying it has no physical existence and is completely vitual..Actually in my page, all 3 script tags have their paths begin with /myapp..but i can locate 2 js (engine.js and util.js)..only MyScript.js I am unable to find.. – copenndthagen Apr 20 '11 at 10:22
  • Yes, MyScript.js has no physical existence. – Vik David Apr 20 '11 at 10:52
  • Cool..So I assume that might be because it is kind of a standard file and never needs any kind of editing..If that is the case, my only question is all the 3 .js files seem to be standard files..Is there any application specific js in DWR.. I'll close the question once I have this answer.. Thanks a lot for your help..You have explained the DWR concepts in an excellent way.. – copenndthagen Apr 20 '11 at 11:09
  • engine.js and util.js are standard DWR files used by everyone (I use them also). Myscript.js is application specific to *your* application, which is why it has no physical existence. – Vik David Apr 20 '11 at 11:32