com.smartgwt.client.widgets

## Class DataContext

- java.lang.Object
- - com.smartgwt.client.core.JsObject
  - - com.smartgwt.client.core.DataClass
    - - com.smartgwt.client.widgets.DataContext

- All Implemented Interfaces:
    com.google.gwt.event.shared.HasHandlers

      public class DataContext
      extends DataClass

  A mapping from `DataSource` IDs to specific `Records`.

  To understand how `dataContext` is used to automatically populate `DataBoundComponents`, see `Canvas.autoPopulateData`.

  For example, in SmartGWT:

          Record customerRecord = new Record();
          customerRecord.setAttribute("customerNumber", "15");
          customerRecord.setAttribute("name", "Trish Joiner");

          Record employeeRecord = new Record();
          employeeRecord.setAttribute("employeeID", "4231");
          employeeRecord.setAttribute("name", "Fred Smith");

          DataContext dataContext = new DataContext();
          dataContext.addMapping("Customer", customerRecord);
          dataContext.addMapping("Employee", employeeRecord);

- - ### Field Summary

    - ### Fields inherited from class com.smartgwt.client.core.DataClass

      `factoryCreated, factoryProperties`

    - ### Fields inherited from class com.smartgwt.client.core.JsObject

      `jsObj`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DataContext()`
    `DataContext(com.google.gwt.core.client.JavaScriptObject jsObj)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `DataContext` | `addDataSourceRecord(java.lang.String dataSourceID, Record record)`
    `java.util.Set<java.lang.String>` | `getBoundDataSources()` Returns set of all DataSource IDs currently bound for this DataContext.
    `Record` | `getDataSourceRecord(DataSource dataSource)` Returns record bound to the DataSource.
    `Record` | `getDataSourceRecord(java.lang.String dataSourceID)` Returns record bound to the DataSource.
    `java.util.Map<java.lang.String,java.lang.Object>` | `getDataSourceRecordBindings()` Returns all current DataSource-to-Record and DataSource-to-Record[] bindings for this DataContext.
    `java.lang.Object` | `getDataSourceRecords(DataSource dataSource)` Returns record(s) bound to the DataSource as Record or Record[].
    `java.lang.Object` | `getDataSourceRecords(java.lang.String dataSourceID)` Returns record(s) bound to the DataSource as Record or Record[].
    `static DataContext` | `getOrCreateRef(com.google.gwt.core.client.JavaScriptObject jsObj)`
    `java.lang.Object` | `getSharedJavaObject(java.lang.String id)` Returns the POJO bound to this id.
    `java.lang.Object` | `removeDataSourceRecords(DataSource dataSource)` Removes any record binding(s) for the DataSource.
    `java.lang.Object` | `removeDataSourceRecords(java.lang.String dataSourceID)` Removes any record binding(s) for the DataSource.
    `DataContext` | `setDataSourceRecord(DataSource dataSource, Record record)` Binds the DataSource to the supplied record.
    `DataContext` | `setDataSourceRecord(java.lang.String dataSourceID, Record record)` Binds the DataSource to the supplied record.
    `DataContext` | `setDataSourceRecords(DataSource dataSource, Record... record)` Binds the DataSource to the supplied records, as an array.
    `DataContext` | `setDataSourceRecords(java.lang.String dataSourceID, Record... record)` Binds the DataSource to the supplied records, as an array.
    `DataContext` | `setSharedJavaObject(java.lang.String id, java.lang.Object sharedObject)` Binds the id to the supplied POJO.

    - ### Methods inherited from class com.smartgwt.client.core.DataClass

      `applyFactoryProperties, doAddHandler, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsDoubleArray, getAttributeAsElement, getAttributeAsFloat, getAttributeAsInt, getAttributeAsIntArray, getAttributeAsJavaScriptObject, getAttributeAsLong, getAttributeAsMap, getAttributeAsObject, getAttributeAsRecord, getAttributeAsString, getAttributeAsStringArray, getAttributes, getHandlerCount, isFactoryCreated, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttributeAsJavaObject, setFactoryCreated`

    - ### Methods inherited from class com.smartgwt.client.core.JsObject

      `equals, getJsObj, hashCode, isCreated, setJavaScriptObject, setJsObj`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DataContext

          public DataContext()

    - #### DataContext

          public DataContext(com.google.gwt.core.client.JavaScriptObject jsObj)

  - ### Method Detail

    - #### getOrCreateRef

          public static DataContext getOrCreateRef(com.google.gwt.core.client.JavaScriptObject jsObj)

    - #### setDataSourceRecord

          public DataContext setDataSourceRecord(DataSource dataSource,
                                                 Record record)

      Binds the DataSource to the supplied record.
      Parameters:
        `dataSource` -
        `record` -
      Returns:
        `DataContext` instance, for chaining setter calls

    - #### setDataSourceRecord

          public DataContext setDataSourceRecord(java.lang.String dataSourceID,
                                                 Record record)

      Binds the DataSource to the supplied record.
      Parameters:
        `dataSourceID` -
        `record` -
      Returns:
        `DataContext` instance, for chaining setter calls

    - #### setDataSourceRecords

          public DataContext setDataSourceRecords(DataSource dataSource,
                                                  Record... record)

      Binds the DataSource to the supplied records, as an array.
      Parameters:
        `dataSource` -
        `record` -
      Returns:
        `DataContext` instance, for chaining setter calls

    - #### setDataSourceRecords

          public DataContext setDataSourceRecords(java.lang.String dataSourceID,
                                                  Record... record)

      Binds the DataSource to the supplied records, as an array.
      Parameters:
        `dataSource` -
        `record` -
      Returns:
        `DataContext` instance, for chaining setter calls

    - #### addDataSourceRecord

          public DataContext addDataSourceRecord(java.lang.String dataSourceID,
                                                 Record record)

    - #### getDataSourceRecords

          public java.lang.Object getDataSourceRecords(DataSource dataSource)

      Returns record(s) bound to the DataSource as Record or Record[].
      Parameters:
        `dataSource` -
      Returns:
        bound record(s), or null

    - #### getDataSourceRecords

          public java.lang.Object getDataSourceRecords(java.lang.String dataSourceID)

      Returns record(s) bound to the DataSource as Record or Record[].
      Parameters:
        `dataSourceID` -
      Returns:
        bound record(s), or null

    - #### getDataSourceRecord

          public Record getDataSourceRecord(DataSource dataSource)

      Returns record bound to the DataSource. If an array of records is bound to the DataSource, returns the first one.
      Parameters:
        `dataSource` -
      Returns:
        bound record, or null

    - #### getDataSourceRecord

          public Record getDataSourceRecord(java.lang.String dataSourceID)

      Returns record bound to the DataSource. If an array of records is bound to the DataSource, returns the first one.
      Parameters:
        `dataSourceID` -
      Returns:
        bound record, or null

    - #### removeDataSourceRecords

          public java.lang.Object removeDataSourceRecords(DataSource dataSource)

      Removes any record binding(s) for the DataSource.
      Parameters:
        `dataSource` -
      Returns:
        bound record(s), or null

    - #### removeDataSourceRecords

          public java.lang.Object removeDataSourceRecords(java.lang.String dataSourceID)

      Removes any record binding(s) for the DataSource.
      Parameters:
        `dataSourceID` -
      Returns:
        bound record(s), or null

    - #### setSharedJavaObject

          public DataContext setSharedJavaObject(java.lang.String id,
                                                 java.lang.Object sharedObject)

      Binds the id to the supplied POJO.

      Passing POJOs to a child window via this API is "super experimental" (beyond the feature itself, which is experimental). To support this, you must declare the "typeSync" linker in your GWT project:

               <add-linker name="typeSync"/>

      Parameters:
        `id` - identifier for POJO
        `sharedobject` - POJO to bind
      Returns:
        `DataContext` instance, for

    - #### getSharedJavaObject

          public java.lang.Object getSharedJavaObject(java.lang.String id)

      Returns the POJO bound to this id.

      Passing POJOs to a child window via this API is "super experimental" (beyond the feature itself, which is experimental). To support this, you must declare the "typeSync" linker in your GWT project:

               <add-linker name="typeSync"/>

      Parameters:
        `id` - identifier for POJO
      Returns:
        bound POJO, or null

    - #### getDataSourceRecordBindings

          public java.util.Map<java.lang.String,java.lang.Object> getDataSourceRecordBindings()

      Returns all current DataSource-to-Record and DataSource-to-Record[] bindings for this DataContext.
      Returns:
        map of DataSource IDs to records

    - #### getBoundDataSources

          public java.util.Set<java.lang.String> getBoundDataSources()

      Returns set of all DataSource IDs currently bound for this DataContext.
      Returns:
        bound DataSource IDs