Spring WebFlow のデフォルトの日付形式は「yyyy-MM-dd」です。
別のフォーマットに変更するには?たとえば、「dd.mm.yyyy」です。
Spring WebFlow のデフォルトの日付形式は「yyyy-MM-dd」です。
別のフォーマットに変更するには?たとえば、「dd.mm.yyyy」です。
投稿が遅くなり申し訳ありませんが、ここにあなたがしなければならないことがあります。Spring Webflow はカスタム データ バインディングを行います。これは、Spring MVC が行う方法に似ています。ただし、違いはそれを処理する場所です。Spring MVC は、コントローラー レベルでそれを処理します ( @InitBinder を使用)。
Spring webflow はバインディング レベルでそれを行います。トランジション Webflow を実行する前に、すべてのパラメーター値をオブジェクトにバインドし、フォームを検証して (validate="true" の場合)、検証が成功するとトランジションを呼び出します。
あなたがする必要があるのは、Webflowに日付をバインドする手段を変更させることです。これを行うには、カスタム コンバーターを記述します。
まず、変換サービスが必要です。
@Component("myConversionService")
public class MyConversionService extends DefaultConversionService {
public void MyConversionService() {
}
}
Webflow はこのサービスを使用して、説明する必要がある特別なバインディングを決定します。ここで、特定の日付バインダーを記述します (Webflow のデフォルトの日付バインダーは上書きすることに注意してください)。
@Component
public class MyDateToString extends StringToObject {
@Autowired
public MyDateToString(MyConversionService conversionService) {
super(Date.class);
conversionService.addConverter(this);
}
@Override
protected Object toObject(String string, Class targetClass) throws Exception {
try{
return new SimpleDateFormat("MM\dd\yyyy").parse(string);//whatever format you want
}catch(ParseException ex){
throw new ConversionExecutionException(string, String.class, targetClass, Date.class);//invokes the typeMissmatch
}
}
}
このBeanを作成することでそれを達成しました:
@Component(value = "applicationConversionService") public class ApplicationConversionServiceFactoryBean extends FormattingConversionServiceFactoryBean {
@Override protected void installFormatters(FormatterRegistry registry) { // Register the default date formatter provided by Spring registry.addFormatter(new DateFormatter("dd/MM/yyyy")); } }
次のようにBeanを登録しました:
<bean id="defaultConversionService" class="org.springframework.binding.convert.service.DefaultConversionService">
<constructor-arg ref="applicationConversionService" />
</bean>
次に参照元:
<mvc:annotation-driven conversion-service="applicationConversionService" />
と:
<!-- Enables custom conversion, validation and sets a custom vew factory creator on Spring Webflow -->
<webflow:flow-builder-services id="flowBuilderServices" conversion-service="defaultConversionService" validator="validator" view-factory-creator="mvcViewFactoryCreator" />
この構成では、私にとってはうまく機能します。お役に立てば幸いです。
私はそれが次のようでなければならないと思います:
StringToDate std = new StringToDate();
std.setPattern("dd.MM.yyyy");