Search in sources :

Example 1 with ConfigurablePropertyAccessor

use of cn.taketoday.beans.ConfigurablePropertyAccessor in project today-infrastructure by TAKETODAY.

the class AbstractPropertyBindingResult method getCustomEditor.

/**
 * Retrieve the custom PropertyEditor for the given field, if any.
 *
 * @param fixedField the fully qualified field name
 * @return the custom PropertyEditor, or {@code null}
 */
@Nullable
protected PropertyEditor getCustomEditor(String fixedField) {
    ConfigurablePropertyAccessor propertyAccessor = getPropertyAccessor();
    Class<?> targetType = propertyAccessor.getPropertyType(fixedField);
    PropertyEditor editor = propertyAccessor.findCustomEditor(targetType, fixedField);
    if (editor == null) {
        editor = BeanUtils.findEditorByConvention(targetType);
    }
    return editor;
}
Also used : PropertyEditor(java.beans.PropertyEditor) ConfigurablePropertyAccessor(cn.taketoday.beans.ConfigurablePropertyAccessor) Nullable(cn.taketoday.lang.Nullable)

Example 2 with ConfigurablePropertyAccessor

use of cn.taketoday.beans.ConfigurablePropertyAccessor in project today-framework by TAKETODAY.

the class WebDataBinder method adaptEmptyArrayIndices.

/**
 * Check for property values with names that end on {@code "[]"}. This is
 * used by some clients for array syntax without an explicit index value.
 * If such values are found, drop the brackets to adapt to the expected way
 * of expressing the same for data binding purposes.
 *
 * @param values the property values to be bound (can be modified)
 */
protected void adaptEmptyArrayIndices(PropertyValues values) {
    ConfigurablePropertyAccessor propertyAccessor = getPropertyAccessor();
    for (PropertyValue pv : values) {
        String name = pv.getName();
        if (name.endsWith("[]")) {
            String field = name.substring(0, name.length() - 2);
            if (propertyAccessor.isWritableProperty(field) && !values.contains(field)) {
                values.add(field, pv.getValue());
            }
            values.remove(pv);
        }
    }
}
Also used : PropertyValue(cn.taketoday.beans.PropertyValue) ConfigurablePropertyAccessor(cn.taketoday.beans.ConfigurablePropertyAccessor)

Example 3 with ConfigurablePropertyAccessor

use of cn.taketoday.beans.ConfigurablePropertyAccessor in project today-framework by TAKETODAY.

the class AbstractPropertyBindingResult method getCustomEditor.

/**
 * Retrieve the custom PropertyEditor for the given field, if any.
 *
 * @param fixedField the fully qualified field name
 * @return the custom PropertyEditor, or {@code null}
 */
@Nullable
protected PropertyEditor getCustomEditor(String fixedField) {
    ConfigurablePropertyAccessor propertyAccessor = getPropertyAccessor();
    Class<?> targetType = propertyAccessor.getPropertyType(fixedField);
    PropertyEditor editor = propertyAccessor.findCustomEditor(targetType, fixedField);
    if (editor == null) {
        editor = BeanUtils.findEditorByConvention(targetType);
    }
    return editor;
}
Also used : PropertyEditor(java.beans.PropertyEditor) ConfigurablePropertyAccessor(cn.taketoday.beans.ConfigurablePropertyAccessor) Nullable(cn.taketoday.lang.Nullable)

Example 4 with ConfigurablePropertyAccessor

use of cn.taketoday.beans.ConfigurablePropertyAccessor in project today-framework by TAKETODAY.

the class WebDataBinder method checkFieldDefaults.

/**
 * Check the given property values for field defaults,
 * i.e. for fields that start with the field default prefix.
 * <p>The existence of a field defaults indicates that the specified
 * value should be used if the field is otherwise not present.
 *
 * @param values the property values to be bound (can be modified)
 * @see #getFieldDefaultPrefix
 */
protected void checkFieldDefaults(PropertyValues values) {
    String fieldDefaultPrefix = getFieldDefaultPrefix();
    if (fieldDefaultPrefix != null) {
        ConfigurablePropertyAccessor propertyAccessor = getPropertyAccessor();
        for (PropertyValue pv : values.toArray()) {
            if (pv.getName().startsWith(fieldDefaultPrefix)) {
                String field = pv.getName().substring(fieldDefaultPrefix.length());
                if (propertyAccessor.isWritableProperty(field) && !values.contains(field)) {
                    values.add(field, pv.getValue());
                }
                values.remove(pv);
            }
        }
    }
}
Also used : PropertyValue(cn.taketoday.beans.PropertyValue) ConfigurablePropertyAccessor(cn.taketoday.beans.ConfigurablePropertyAccessor)

Example 5 with ConfigurablePropertyAccessor

use of cn.taketoday.beans.ConfigurablePropertyAccessor in project today-framework by TAKETODAY.

the class WebDataBinder method checkFieldMarkers.

/**
 * Check the given property values for field markers,
 * i.e. for fields that start with the field marker prefix.
 * <p>The existence of a field marker indicates that the specified
 * field existed in the form. If the property values do not contain
 * a corresponding field value, the field will be considered as empty
 * and will be reset appropriately.
 *
 * @param values the property values to be bound (can be modified)
 * @see #getFieldMarkerPrefix
 * @see #getEmptyValue(String, Class)
 */
protected void checkFieldMarkers(PropertyValues values) {
    String fieldMarkerPrefix = getFieldMarkerPrefix();
    if (fieldMarkerPrefix != null) {
        ConfigurablePropertyAccessor propertyAccessor = getPropertyAccessor();
        for (PropertyValue pv : values.toArray()) {
            if (pv.getName().startsWith(fieldMarkerPrefix)) {
                String field = pv.getName().substring(fieldMarkerPrefix.length());
                if (propertyAccessor.isWritableProperty(field) && !values.contains(field)) {
                    Class<?> fieldType = propertyAccessor.getPropertyType(field);
                    values.add(field, getEmptyValue(field, fieldType));
                }
                values.remove(pv);
            }
        }
    }
}
Also used : PropertyValue(cn.taketoday.beans.PropertyValue) ConfigurablePropertyAccessor(cn.taketoday.beans.ConfigurablePropertyAccessor)

Aggregations

ConfigurablePropertyAccessor (cn.taketoday.beans.ConfigurablePropertyAccessor)8 PropertyValue (cn.taketoday.beans.PropertyValue)6 Nullable (cn.taketoday.lang.Nullable)2 PropertyEditor (java.beans.PropertyEditor)2