|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||
@Retention(value=SOURCE) @Target(value=METHOD) public @interface OnReceive
Static methods in classes annotated by Model
can be marked by this annotation to establish a
JSON
communication point.
The associated model class then gets new method to invoke a network
connection. Example follows:
When the server returns@Model(className="MyModel", properties={@Property(name = "people", type=Person.class, array=true) }) class MyModelImpl {@Model(className="Person", properties={@Property(name = "firstName", type=String.class),@Property(name = "lastName", type=String.class) }) static class PersonImpl {@ComputedPropertystatic String fullName(String firstName, String lastName) { return firstName + " " + lastName; } }@OnReceive(url = "{protocol}://your.server.com/person/{name}") static void getANewPerson(MyModel m, Person p) { alert("Adding " + p.getFullName() + '!'); m.getPeople().add(p); } // the above will generate methodgetANewPersonin classMyModel. // withprotocolandnamearguments // which asynchronously contacts the server and in case of success calls // your@OnReceivewith parsed in data@Functionstatic void requestSmith(MyModel m) { m.getANewPerson("http", "Smith"); } }
{ "firstName" : "John", "lastName" : "Smith" }
the browser will show alert message Adding John Smith!.
| Required Element Summary | |
|---|---|
String |
url
The URL to connect to. |
| Optional Element Summary | |
|---|---|
Class<?> |
data
The model class to be send to the server as JSON data. |
String |
jsonp
Support for JSONP requires a callback from the server generated page to a function defined in the system. |
String |
method
The HTTP transfer method to use. |
| Element Detail |
|---|
public abstract String url
public abstract String jsonp
jsonp attribute
one turns on the JSONP
transmission and specifies the name of the property. The property should
also be used in the url() attribute on appropriate place.
public abstract Class<?> data
transport methods
(like "PUT" and "POST") require the
data to be specified.
@Model annotationpublic abstract String method
"GET".
Other typical methods include "HEAD",
"DELETE", "POST", "PUT".
The last two mentioned methods require data() to be specified.
When JSONP transport is requested, the method
has to be "GET".
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | ||||||||