Class DataContext

All Implemented Interfaces:
HasHandlers

public class DataContext extends DataClass
A mapping from DataSource IDs to specific Records, and optionally, cross-component Criteria via the reserved sharedCriteria key.

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

Shared Criteria

The optional sharedCriteria key holds AdvancedCriteria that are automatically combined into every matching DBC's fetch via DataSource.combineCriteria(). Matching is by fieldName: each sub-criterion applies only to components whose DataSource contains a field of that name with a compatible type (see Canvas.handleDataContextCriteria() for type compatibility rules).

This is the mechanism that powers cross-component filtering: slicer chips, date-range pickers, and other global filters publish criteria into sharedCriteria, and all subscribing components re-fetch accordingly.

RelativeDate values are fully supported inside sharedCriteria and are resolved at fetch time, so a criterion like { fieldName:"orderDate", operator:"greaterThan", value:{ _constructor: "RelativeDate", value:"-1m" } } is kept in relative form and re-evaluated on each fetch.

Shared criteria are also provided to rule context under the path dataContext.sharedCriteria, enabling dynamic criteria and visibility rules to react to the current global filter state.

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);
  
  • Constructor Details

    • DataContext

      public DataContext()
    • DataContext

      public DataContext(JavaScriptObject jsObj)
  • Method Details

    • getOrCreateRef

      public static DataContext getOrCreateRef(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(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(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(String dataSourceID, Record record)
    • getDataSourceRecords

      public 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 Object getDataSourceRecords(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(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 Object removeDataSourceRecords(DataSource dataSource)
      Removes any record binding(s) for the DataSource.
      Parameters:
      dataSource -
      Returns:
      bound record(s), or null
    • removeDataSourceRecords

      public Object removeDataSourceRecords(String dataSourceID)
      Removes any record binding(s) for the DataSource.
      Parameters:
      dataSourceID -
      Returns:
      bound record(s), or null
    • setSharedJavaObject

      public DataContext setSharedJavaObject(String id, 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 Object getSharedJavaObject(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 Map<String,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 Set<String> getBoundDataSources()
      Returns set of all DataSource IDs currently bound for this DataContext.
      Returns:
      bound DataSource IDs