Prev | Current Page 242 | Next

Frank Zammetti

"Practical DWR 2 Projects"


The actual annotations couldn??™t be simpler. Let??™s start with a simple class that we wish to
remote, as shown in Listing 3-4.
Listing 3-4. A Simple Class That We??™ll Configure with Annotations
public class RemoteClass {
public String myMethod(String inParam) {
return inParam + " returned";
}
}
Now, to annotate this and prepare it for DWR use, we have only to add a few annotations,
the result being the code in Listing 3-5.
CHAPTER 3 n ADVANCED DWR 123
Listing 3-5. That Same Simple Class All Annotated for DWR??™s Gratification
@RemoteProxy
public class RemoteClass {
@RemoteMethod
public String myMethod(String inParam) {
return inParam + " returned";
}
}
And just like that, we can now call the myMethod() method of the RemoteClass class using
DWR! The @RemoteProxy annotation indicates the class can be remoted, and the @RemoteMethod
annotation indicates the method can be called.
Any method in the class not annotated will not be available to DWR. If you wish to have a
different JavaScript object name than the name of the class (RemoteClass in this case), you add
a name attribute to the @RemoteProxy annotation like so:
@RemoteProxy(name="SomeClassName")
When you need to deal with beans that you want to allow DWR to convert, there are the
@DataTransferObject and @RemoteProperty annotations, their usage shown in Listing 3-6.


Pages:
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254