Esempio n. 1
0
 private static Object getValue(Object bean, String fieldName) throws Exception {
   final String getter = RichBeanUtils.getGetterName(fieldName);
   try {
     return bean.getClass().getMethod(getter).invoke(bean);
   } catch (java.lang.NoSuchMethodException ne) {
     final String isser = RichBeanUtils.getIsserName(fieldName);
     return bean.getClass().getMethod(isser).invoke(bean);
   }
 }
Esempio n. 2
0
 /**
  * Get the ui field out of the object container.
  *
  * @param fieldName
  * @param uiObject
  * @return IFieldWidget or null if is not an IFieldWidget instance
  * @throws Exception
  * @throws NoSuchMethodException
  * @throws SecurityException
  * @throws InvocationTargetException
  * @throws IllegalAccessException
  * @throws IllegalArgumentException
  */
 public static IFieldWidget getFieldWidget(final String fieldName, final Object uiObject)
     throws Exception {
   final String methodName = RichBeanUtils.getGetterName(fieldName);
   final Method getter = uiObject.getClass().getMethod(methodName);
   final Object box = getter.invoke(uiObject);
   if (box instanceof IFieldWidget) {
     return (IFieldWidget) box;
   }
   return null;
 }
Esempio n. 3
0
  /**
   * Set the value of a single field specified by field name in the bean from the ui.
   *
   * @param uiObject
   * @param bean
   * @param fieldName
   * @throws Exception
   */
  public static void uiToBean(final Object uiObject, final Object bean, final String fieldName)
      throws Exception {

    if (fieldName == null)
      throw new Exception("Null fieldName passed to uiToBean. Please set the field name.");

    final IFieldWidget box = BeanUIWithoutOSGi.getFieldWidget(fieldName, uiObject);
    if (box == null) return; // Not all properties have to be in the UI.

    if (!box.isActivated()) return;
    final Object ob = box.getValue();
    if (ob != null && !isNaN(ob) && !isInfinity(ob)) {
      RichBeanUtils.setBeanValue(bean, fieldName, ob);
    } else {
      // Required to fix fields inside a list editor being edited to no value.
      if (ob != null) {
        final Method setter =
            bean.getClass().getMethod(RichBeanUtils.getSetterName(fieldName), ob.getClass());
        setter.invoke(bean, ob.getClass().cast(null));
      }
    }
  }