替换标准组件
可以注册新组件并使用 replaceComponent() 替换标准 Flow UI 组件。
例如,以下是一个完整的配置,将应用程序中所有 TypedDatePicker 替换为带预定义属性的版本。该配置保留了标准的 datePicker XML 元素和加载器。
新的 datePicker 组件:
public class ExtendedDatePicker<V extends Comparable> extends TypedDatePicker<V> {
public static final String FAST_INPUT_DATE_FORMAT = "ddMMyyyy";
@Override
protected void initComponent() {
super.initComponent();
getThemeNames().set("align-left", true);
getI18n().setDateFormats(
messages.getMessage("dateFormat"),
FAST_INPUT_DATE_FORMAT
);
}
}
注册配置:
@Configuration
public class ComponentRegistrationConfiguration {
@Bean
public ComponentRegistration datePicker() {
return ComponentRegistrationBuilder.create(ExtendedDatePicker.class)
.withComponentLoader("datePicker", DatePickerLoader.class)
.replaceComponent(TypedDatePicker.class)
.build();
}
}
通过这个方式可以设置全局的自定义行为,而同时保留对已有的视图和 XML 的兼容性。
本页是否有帮助?
感谢您的反馈