Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Feature Request: Callback for FormItem:getSelectedRecord()

    Hello,

    is there a possibility to extend the Method FormItem:getSelectedRecord() with a callback Parameter, which is fired when the related data is fetched by the datasource?

    Regards
    Andreas

    #2
    If I'm not mistaken, the getSelectedRecord() method acts on records already selected. So if you populate say a SelectItem and then choose item from the list, you can confirm details of what has been selected in say the click handler. Just my thoughts.

    Comment


      #3
      Right, if you select a record all is working correctly. But If you populate the values via editSelectedData or editRecord you never get the full related record.

      I've already tried to set these properties (without any success in getting the related record):

      Code:
      siteItem.setAutoFetchData(true);
      siteItem.setFetchDisplayedFieldsOnly(false);
      siteItem.setFetchMissingValues(true);
      siteItem.setAlwaysFetchMissingValues(true);
      siteItem.addDataArrivedHandler(new DataArrivedHandler() {
      	@Override
      	public void onDataArrived(DataArrivedEvent event) {
      		// this is not called for editRecord or editSelectedData
      	}
      });
      btw. if the related record is already in the cache of the datasource, this record is returned from the method getSelectedRecord().

      Comment


        #4
        No need, if you have a unique value for the valueField you can make Criteria from it and call DataSource.fetchData().

        Comment


          #5
          Originally posted by Isomorphic View Post
          No need, if you have a unique value for the valueField you can make Criteria from it and call DataSource.fetchData().
          This is how I worked around this issue. Perhaps you can add a convinience method like this:

          Code:
          public void getSelectedRecord(DSCallback callback) {
          	DataSource ds = getOptionDataSource();
          	if (ds == null) {
          		throw new IllegalStateException("A datasource must be specified");
          	}
          	ListGridRecord record = getSelectedRecord();
          	if (record != null) {
          		callback.execute(new DSResponse(ds.getID(), DSOperationType.FETCH, record), null, null);
          		return;
          	}
          	if (getValue() == null) {
          		callback.execute(new DSResponse(ds.getID(), DSOperationType.FETCH), null, null);
          		return;
          	}
          	DataSourceField keyField = ds.getPrimaryKeyField();
          	if (keyField == null) {
          		throw new IllegalStateException("The datasource has no primaryKey field");
          	}
          	Criteria criteria = new Criteria();
          	switch (keyField.getType()) {
          		case TEXT:
          			criteria.addCriteria(keyField.getName(), getValueAsString());
          			break;
          		case INTEGER:
          			criteria.addCriteria(keyField.getName(), (Integer) getValue());
          			break;
          		default:
          			throw new IllegalStateException(
          					"The type " + keyField.getType() + " of the primaryKey is not supported");
          
          	}
          	// TODO perhaps caching the returned value as SelectedRecord so subsequent calls to this method doesn't need to call the Datasource
          	ds.fetchData(criteria, callback);
          }

          Comment

          Working...
          X