Wiki source code of Using DWR with XWiki plugins
Last modified by Vincent Massol on 2007/11/07 08:22
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | |||
| 2 | #info("This section is related to *third-party software* which can be useful for XWiki plugin developers") | ||
| 3 | |||
| 4 | #info("The information available on this page originates from the [DWR online manual>http://getahead.org/dwr/documentation], which is the original and best source of information regarding DWR.") | ||
| 5 | |||
| 6 | #toc("") | ||
| 7 | |||
| 8 | 1 $doc.title | ||
| 9 | |||
| 10 | [DWR>http://getahead.org/dwr/overview/dwr] is a Java open source library which allows you to write Ajax web sites. | ||
| 11 | |||
| 12 | 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. | ||
| 13 | |||
| 14 | 1.1 How it works | ||
| 15 | |||
| 16 | * run DWR as a servlet in your container. | ||
| 17 | * the servlet will take care of making java classes accessible for javascript. | ||
| 18 | ** For each java class, the servlet will automatically generate a *.js file. | ||
| 19 | ** 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. | ||
| 20 | |||
| 21 | 1.1 Example | ||
| 22 | |||
| 23 | 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 the <code>webapps/xwiki/WEB-INF/lib</code> folder if you have installed xwiki from the installer. | ||
| 24 | |||
| 25 | 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. | ||
| 26 | |||
| 27 | After deciding what exactly you want to share, you have to specify it in the <code>dwr.xml</code> file, located in your webapp's <code>WEB-INF</code>. If you have installed xwiki from the installer, it would reside in <code>webapps/xwiki/WEB-INF</code>. | ||
| 28 | |||
| 29 | 1.1.1 Sharing a class | ||
| 30 | |||
| 31 | It means you will be able to use <code>public static</code> methods of your class. | ||
| 32 | Add an entry in the <code>dwr.xml</code> file |