Using DWR with XWiki plugins
DWR is a Java open source library which allows you to write Ajax web sites. It allows code in a browser to use Java functions running on a web server just as if it was in the browser. It works on servlets containers.How it works
- run DWR as a servlet in your container.
- the servlet will take care of making java classes accessible for javascript.
- For each java class, the servlet will automatically generate a *.js file.
- So you have to include that *.js file in your javascript pages. The file does not actually exist on the server filesystem, but is generated by the DWR servlet.
Example
First install DWR. That's the easy part, just download the JAR file from http://getahead.org/dwr/download and put it in the same place as the other JAR files for your webapp classes - in thewebapps/xwiki/WEB-INF/lib folder if you have installed xwiki from the installer.
Then you have to choose whether you want to share an instance of a Java class, or the class itself. It will determine the constructor you want DWR to use for the class you share. Whichever you choose, all public methods, static or not, of the class will be shared by DWR. But the methods you will be able to use in Javascript depend on which constructor you have specified in DWR for your class.
After deciding what exactly you want to share, you have to specify it in the dwr.xml file, located in your webapp's WEB-INF. If you have installed xwiki from the installer, it would reside in webapps/xwiki/WEB-INF.
Sharing a class
It means you will be able to usepublic static methods of your class.
Add an entry in the dwr.xml file
Version 1.12 last modified by VincentMassol on 07/11/2007 at 08:22
Document data
Attachments:
No attachments for this document
Comments: 0