You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gwt-connector.asciidoc 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. ---
  2. title: Integrating the Two Sides with a Connector
  3. order: 4
  4. layout: page
  5. ---
  6. [[gwt.connector]]
  7. = Integrating the Two Sides with a Connector
  8. A client-side widget is integrated with a server-side component with a
  9. __connector__. A connector is a client-side class that communicates changes to
  10. the widget state and events to the server-side.
  11. A connector normally gets the state of the server-side component by the __shared
  12. state__, described later in
  13. <<dummy/../../../framework/gwt/gwt-shared-state#gwt.shared-state,"Shared
  14. State">>.
  15. [[gwt.connector.basic]]
  16. == A Basic Connector
  17. The basic tasks of a connector is to hook up to the widget and handle events
  18. from user interaction and changes received from the server. A connector also has
  19. a number of routine infrastructure methods which need to be implemented.
  20. [source,java]
  21. ----
  22. @Connect(MyComponent.class)
  23. public class MyComponentConnector
  24. extends AbstractComponentConnector {
  25. @Override
  26. public MyComponentWidget getWidget() {
  27. return (MyComponentWidget) super.getWidget();
  28. }
  29. @Override
  30. public MyComponentState getState() {
  31. return (MyComponentState) super.getState();
  32. }
  33. @Override
  34. public void onStateChanged(StateChangeEvent stateChangeEvent)
  35. {
  36. super.onStateChanged(stateChangeEvent);
  37. // Do something useful
  38. final String text = getState().text;
  39. getWidget().setText(text);
  40. }
  41. }
  42. ----
  43. Here, we handled state change with the crude [methodname]#onStateChanged()#
  44. method that is called when any of the state properties is changed. A finer and
  45. simpler handling is achieved by using the [classname]#@OnStateChange# annotation
  46. on a handler method for each property, or by [classname]#@DelegateToWidget# on a
  47. shared state property, as described later in
  48. <<dummy/../../../framework/gwt/gwt-shared-state#gwt.shared-state,"Shared
  49. State">>.
  50. [[gwt.connector.communication]]
  51. == Communication with the Server-Side
  52. The main task of a connector is to communicate user interaction with the widget
  53. to the server-side and receive state changes from the server-side and relay them
  54. to the widget.
  55. Server-to-client communication is normally done using a __shared state__, as
  56. described in
  57. <<dummy/../../../framework/gwt/gwt-shared-state#gwt.shared-state,"Shared
  58. State">>, as well as RPC calls. The serialization of the state data is handled
  59. completely transparently.
  60. ifdef::web[]
  61. Once the client-side engine receives the changes from the server, it reacts to
  62. them by creating and notifying connectors that in turn manage widgets. This is
  63. described in
  64. <<dummy/../../../framework/gwt/gwt-advanced#gwt.advanced.phases,"Client-Side
  65. Processing Phases">> in more
  66. detail.
  67. endif::web[]
  68. For client-to-server communication, a connector can make remote procedure calls
  69. (RPC) to the server-side. Also, the server-side component can make RPC calls to
  70. the connector. For a thorough description of the RPC mechanism, refer to
  71. <<dummy/../../../framework/gwt/gwt-rpc#gwt.rpc,"RPC Calls Between Client- and
  72. Server-Side">>.