DWR configuration XML file
The DWR configuration file for, e.g., module "foo" is
work/src/edu/institution/kuali/module/foo/dwr-foo.xml. If your module doesn't have one already, then you need to create it and add a reference to it in your module's
KualiModule bean, for example:
You can list as many "include" methods as needed. See the DWR documentation on Creators for more information.
Converters are what allow DWR to handle complex objects. DWR comes with a standard set of converters which handle all the normal data types (including arrays and collections.) For Kuali BusinessObjects, you will need to add a converter which tells it what to do. You will likely need one of these for the return type of any method which does not return a type in java.lang or java.util. The standard type of converter you will need is a "bean" converter. It accepts a class name and a list of properties which should be exposed. Here is the converter for the Account BusinessObject:
The "match" attribute identifies the class to convert. (Again, wildcards are allowed, but should be avoided.) The "include" parameter is a comma-delimited list of the property names which should be returned when an object of this class is returned from a DWR exposed method call. The list of properties may also include attributes which are other business objects. In that case, you must also define a converter for that object's class as well.
For more information, see the DWR Documentation on Converters.
Including the Script Files
To bring in the service you just defined, you add a script line like:
Including the Script Files in Maintenance Documents
For documents which don't have their own JSP files and are controlled by the Data Dictionary, you include the JS into your code by adding <webScriptFile> tags into the document data dictionary file. You will also want to include at least one additional file which holds the document-specific code which will call the DWR methods. Here is the code from AccountMaintenanceDocument.xml:
Making the Asynchronous Call
These instructions are for making a one-off call for a particular document. If your method would be useful for other documents, consider putting it in that module's objectInfo.js file. (Which lives in work/web-root/scripts/<module ID>.)
Before calling the method, you need to construct an object which handles the results when they return. DWR calls are asynchronous, the call will not block until the method returns. Control is returned to the browser immediately. When DWR sends the results, is uses the given object to handle the results.
So, define a variable as follows:
This defines an object with two properties, each a function. The "callback" function is called when the DWR call returns from the server. It will be passed the converted Java object for use by the method. Information in the data object is accessed just like JavaBean property notation. For Example, the account name would be accessed as "data.accountName" If you embed another business object into the class, you would access it like: "data.chartOfAccounts.finChartOfAccountDescription"
It's easiest to take a look at some of the existing methods in work/web-root/scripts/kfs/objectInfo.js to see how the data is used.
Now, to call the method, you make a call of this form:
Where the first parameters are the actual parameters that the Java method requires. After all the normal parameters, you pass in the dwrReply object that you just created.
At this point, you would put the above code into a method and call that method from an appropriate place in the application (like an onblur handler.)
Making the Asynchronous Call from Maintenance Documents