Ejemplo n.º 1
0
  /**
   * Actively performs the binding from the CForms-form to the ObjectModel wrapped in a jxpath
   * context
   */
  public void doSave(Widget frmModel, JXPathContext jxpc) throws BindingException {
    Widget widget = selectWidget(frmModel, this.fieldId);
    Object value = widget.getValue();
    if (value != null && convertor != null) {
      value = convertor.convertToString(value, convertorLocale, null);
    }

    Object oldValue = jxpc.getValue(this.xpath);
    if (getLogger().isDebugEnabled()) {
      getLogger().debug("value= " + value + " -- oldvalue=" + oldValue);
    }

    boolean update = false;

    if ((value == null && oldValue != null) || value != null && !value.equals(oldValue)) {
      // first update the value itself
      jxpc.createPathAndSetValue(this.xpath, value);

      // now perform any other bindings that need to be performed when the value is updated
      JXPathContext subContext = null;
      try {
        subContext = jxpc.getRelativeContext(jxpc.getPointer(this.xpath));
      } catch (JXPathException e) {
        // if the value has been set to null and the underlying model is a bean, then
        // JXPath will not be able to create a relative context
        if (getLogger().isDebugEnabled()) {
          getLogger()
              .debug("(Ignorable) problem binding field " + widget.getRequestParameterName(), e);
        }
      }
      if (subContext != null) {
        this.updateBinding.saveFormToModel(frmModel, subContext);
      }

      update = true;
    }

    if (getLogger().isDebugEnabled()) {
      getLogger()
          .debug("done saving " + this + " -- value= " + value + " -- on-update == " + update);
    }
  }