public static void mapObjectOnFormModel ( FormModel formModel , Object objectToMap ) { BeanWrapper beanWrapper = new BeanWrapperImpl ( objectToMap ) ; for ( String fieldName : ( Set < String > ) formModel . getFieldNames ( ) ) { try { formModel . getValueModel ( fieldName ) . setValue ( beanWrapper . getPropertyValue ( fieldName ) ) ; } catch ( BeansException be ) { // silently ignoring, just mapping values, so if there's one missing, don't bother } } }
This method tries to map the values of the given object on the valueModels of the formModel . Instead of setting the object as a backing object all valueModels are processed one by one and the corresponding property value is fetched from the objectToMap and set on that valueModel . This triggers the usual buffering etc . just as if the user entered the values .