Ejemplo n.º 1
0
 /**
  * Add a binding in the BindingNode of the specified path.
  *
  * @param path the path of the specified BindingNode in the tree.
  * @param binding the binding to be added to the specified BindingNode.
  * @param varnameSet set with all _var names
  */
 public void addBinding(String path, Binding binding, Set varnameSet) {
   final List nodeids = DataBinder.parseExpression(path, ".");
   if (nodeids.size() <= 0) {
     throw new UiException("Incorrect bean expression: " + path);
   }
   boolean var = varnameSet.contains(nodeids.get(0));
   BindingNode currentNode = this;
   for (final Iterator it = nodeids.iterator(); it.hasNext(); ) {
     final String nodeid = (String) it.next();
     if (nodeid == null) {
       throw new UiException("Incorrect bean expression: " + path);
     }
     BindingNode kidNode = currentNode.getKidNode(nodeid);
     if (kidNode == null) { // if not found, then add one
       if ("/".equals(currentNode._path)) {
         kidNode = new BindingNode(nodeid, var, nodeid, true);
       } else {
         kidNode = new BindingNode(currentNode._path + "." + nodeid, var, nodeid, false);
       }
       currentNode.addKidNode(nodeid, kidNode);
     } else {
       var = var || kidNode._var;
     }
     currentNode = kidNode;
   }
   if (currentNode == this) {
     throw new UiException("Incorrect bean expression: " + path);
   }
   currentNode.addBinding(binding);
   if ("_var".equals(binding.getAttr())) {
     currentNode._innerCollectionNode = DataBinder.hasTemplateOwner(binding.getComponent());
   }
 }
Ejemplo n.º 2
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);
       }
     }
   }
 }
Ejemplo n.º 3
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));
      }
    }