예제 #1
0
 protected void handleEvent(Event event) {
   for (BindingInfo bi : _dataTargets) {
     final Component dt = bi.getComponent();
     final Binding binding = bi.getBinding();
     final DataBinder binder = binding.getBinder();
     final Component dataTarget =
         DataBinder.isTemplate(dt) ? DataBinder.lookupClone(event.getTarget(), dt) : dt;
     if (dataTarget != null) {
       binding.loadAttribute(dataTarget);
     } else { // #bug 2897202
       final List<Component> clones = scanClones(binder, dt);
       for (final Component dataTarget1 : clones) {
         binding.loadAttribute(dataTarget1);
       }
     }
   }
 }
예제 #2
0
    protected void handleEvent(Event event) {
      final Component target = event.getTarget();
      final String triggerEventName = event.getName();
      final List<BindingInfo> tmplist = new ArrayList<BindingInfo>(_dataTargets.size());
      final List<Object> values = new LinkedList<Object>();
      final List<Component> refs = new LinkedList<Component>();
      final List<Binding> bindings = new LinkedList<Binding>();

      // fire onSave for each binding
      for (BindingInfo bi : _dataTargets) {
        final Component dt = bi.getComponent();
        final Binding binding = bi.getBinding();
        final DataBinder binder = binding.getBinder();
        final Component dataTarget =
            DataBinder.isTemplate(dt) ? DataBinder.lookupClone(target, dt) : dt;
        // bug# 1904389: NullPointerException if save-when in collection binding
        // event.getTarget() might not inside the collection item (i.e. row, listitem, etc.)
        // then binder.lookupClone() will return null dataTarget.
        if (dataTarget != null) {
          final Object[] vals = binding.getAttributeValues(dataTarget);
          if (vals != null) {
            tmplist.add(new BindingInfo(binding, dataTarget, vals));
            values.add(vals[0]);
            refs.add(dataTarget);
            bindings.add(binding);
            Events.sendEvent(
                new BindingSaveEvent("onBindingSave", dataTarget, target, binding, vals[0]));
          }
        } else {
          // bi.getComponent a template and a null dataTarget, meaning all collection items has to
          // be handled. Search the owner to iterate all cloned items.
          final List<Component> clones = scanClones(binder, dt);
          for (Component dataTarget1 : clones) {
            final Object[] vals = binding.getAttributeValues(dataTarget1);
            if (vals != null) {
              tmplist.add(new BindingInfo(binding, dataTarget1, vals));
              values.add(vals[0]);
              refs.add(dataTarget1);
              bindings.add(binding);
              Events.sendEvent(
                  new BindingSaveEvent("onBindingSave", dataTarget1, target, binding, vals[0]));
            }
          }
        }
      }

      // fire onValidate for target component
      Events.sendEvent(
          new BindingValidateEvent("onBindingValidate", target, refs, bindings, values));

      // saveAttribute for each binding
      Component loadOnSaveProxy = null;
      Component dataTarget = null;
      DataBinder binder = null;
      final List<Object> loadOnSaveInfos = new ArrayList<Object>(tmplist.size());
      for (BindingInfo bi : tmplist) {
        dataTarget = bi.getComponent();
        final Binding binding = bi.getBinding();
        if (binder == null) {
          binder = binding.getBinder();
        }
        final Object[] vals = bi.getAttributeValues();
        binding.saveAttributeValue(dataTarget, vals, loadOnSaveInfos, triggerEventName);
        if (loadOnSaveProxy == null && dataTarget.isListenerAvailable("onLoadOnSave", true)) {
          loadOnSaveProxy = dataTarget;
        }
      }

      // bug #1895856 : data binding LoadOnSave works only on the last save-when component
      // do loadOnSave
      // if (dataTarget != null) {
      //		Events.postEvent(new Event("onLoadOnSave", dataTarget, loadOnSaveInfos));
      //	}

      // (use first working dataTarget as proxy)
      // feature#2990932, allow disable load-on-save mechanism
      if (loadOnSaveProxy != null && binder.isLoadOnSave()) {
        Events.postEvent(new Event("onLoadOnSave", loadOnSaveProxy, loadOnSaveInfos));
      }
    }