Search in sources :

Example 1 with AbstractSinglePropertyField

use of com.vaadin.flow.component.AbstractSinglePropertyField in project linkki by linkki-framework.

the class TestUiUtil method setUserOriginatedValue.

public static <T> void setUserOriginatedValue(AbstractSinglePropertyField<?, T> field, T value) {
    try {
        Field fieldSupportField = AbstractField.class.getDeclaredField("fieldSupport");
        fieldSupportField.setAccessible(true);
        AbstractFieldSupport<?, ?> fieldSupport = (AbstractFieldSupport<?, ?>) fieldSupportField.get(field);
        Method valueSetter = AbstractFieldSupport.class.getDeclaredMethod("setValue", Object.class, boolean.class, boolean.class);
        valueSetter.setAccessible(true);
        valueSetter.invoke(fieldSupport, value, false, true);
    } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
        throw new RuntimeException("Failed to set user-originated value", e.getCause());
    }
}
Also used : AbstractFieldSupport(com.vaadin.flow.component.internal.AbstractFieldSupport) AbstractSinglePropertyField(com.vaadin.flow.component.AbstractSinglePropertyField) Field(java.lang.reflect.Field) AbstractField(com.vaadin.flow.component.AbstractField) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

AbstractField (com.vaadin.flow.component.AbstractField)1 AbstractSinglePropertyField (com.vaadin.flow.component.AbstractSinglePropertyField)1 AbstractFieldSupport (com.vaadin.flow.component.internal.AbstractFieldSupport)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1