Exemplo n.º 1
0
 /** Get converted value and original value of this Binding. */
 private Object[] getAttributeValues(Component comp) {
   if (!isSavable()
       || _attr.startsWith("_")
       || DataBinder.isTemplate(comp)
       || comp.getPage() == null) {
     return null; // cannot save, a control attribute, or a detached component, skip!
   }
   Object rawval = null;
   try {
     rawval = Fields.get(comp, _attr);
   } catch (NoSuchMethodException ex) {
     // Bug #1813278, Annotations do not work with xhtml tags
     if (comp instanceof DynamicPropertied) {
       final DynamicPropertied dpcomp = (DynamicPropertied) comp;
       if (dpcomp.hasDynamicProperty(_attr)) {
         rawval = dpcomp.getDynamicProperty(_attr);
       } else {
         throw UiException.Aide.wrap(ex);
       }
     } else if (comp.getAttributes()
         .containsKey(
             _attr)) { // Feature #2855116. Get value from component custom-attribute(also a
                       // variable in ZK5).
       rawval = comp.getAttribute(_attr);
     } else {
       throw UiException.Aide.wrap(ex);
     }
   }
   try {
     final Object val = (_converter == null) ? rawval : _converter.coerceToBean(rawval, comp);
     return val == TypeConverter.IGNORE ? null : new Object[] {val, rawval};
   } catch (ClassCastException ex) {
     throw UiException.Aide.wrap(ex);
   }
 }
Exemplo n.º 2
0
  private void myLoadAttribute(Component comp, Object bean) {
    try {
      // since 3.1, 20080416, support bindingArgs for non-supported tag
      // bug #2803575, merge bindingArgs together since a component can have
      // multiple bindings on different attributes.
      Map<Object, Object> bindArgs = cast((Map) comp.getAttribute(DataBinder.ARGS));
      if (bindArgs == null) {
        bindArgs = new HashMap<Object, Object>();
        comp.setAttribute(DataBinder.ARGS, bindArgs);
      }
      if (_args != null) {
        bindArgs.putAll(_args);
        comp.setAttribute(_attr + "_" + DataBinder.ARGS, _args);
      }

      if (_converter != null) {
        bean = _converter.coerceToUi(bean, comp);
        if (bean == TypeConverter.IGNORE) return; // ignore, so don't do Fields.set()
      }

      // Bug #1876198 Error msg appears when load page (databind+CustomConstraint)
      // catching WrongValueException no longer works, check special case and
      // use setRowValue() method directly
      if ((comp instanceof InputElement) && "value".equals(_attr)) {
        Object value = bean;
        Object oldv = null;
        try { // Bug 1879389
          final Method m = comp.getClass().getMethod("getValue");
          oldv = ((InputElement) comp).getRawValue();
          value = Classes.coerce(m.getReturnType(), bean);
        } catch (NoSuchMethodException ex) { // ignore it
        }

        // See both Bug 3000305 and 2874098
        Fields.set(comp, "rawValue", value, _converter == null);
      } else {
        Fields.set(comp, _attr, bean, _converter == null);
      }
    } catch (ClassCastException ex) {
      throw UiException.Aide.wrap(ex);
    } catch (NoSuchMethodException ex) {
      // Bug #1813278, Annotations do not work with xhtml tags
      if (comp instanceof DynamicPropertied) {
        final DynamicPropertied dpcomp = (DynamicPropertied) comp;
        if (dpcomp.hasDynamicProperty(_attr)) {
          // no way to know destination type of the property, use bean as is
          dpcomp.setDynamicProperty(_attr, bean);
        } else {
          throw UiException.Aide.wrap(ex);
        }
      } else { // Feature# 2855116. Save into component custom-attribute(also a variable in ZK5).
        comp.setAttribute(_attr, bean);
      }

      // Bug #1876198 Error msg appears when load page (databind+CustomConstraint)
      // catching WrongValueException no longer works, so mark it out
      /*} catch (WrongValueException ex) {
      	//Bug #1615371, try to use setRawValue()
      	if ("value".equals(_attr)) {
      		try {
      			Fields.set(comp, "rawValue", bean, _converter == null);
      		} catch (Exception ex1) {
      			//exception
      			throw ex;
      		}
      	} else {
      		throw ex;
      	}
      */
    }
  }