public class CustomDateEditor extends PropertyEditorSupportSE
java.text.DateFormat
をサポートする java.util.Date
のプロパティエディター。これは、システム PropertyEditor として使用するためのものではなく、カスタムコントローラーコード内のロケール固有の日付エディターとして使用して、ユーザーが入力した数値文字列を Bean の Date プロパティに解析し、UI フォームにレンダリングします。
Web MVC コードでは、このエディターは通常 binder.registerCustomEditor
に登録されます。
Date
SE, DateFormat
SE, DataBinder.registerCustomEditor(java.lang.Class<?>, java.beans.PropertyEditor)
コンストラクターと説明 |
---|
CustomDateEditor(DateFormatSE dateFormat, boolean allowEmpty) 解析とレンダリングに指定された DateFormat を使用して、新しい CustomDateEditor インスタンスを作成します。 |
CustomDateEditor(DateFormatSE dateFormat, boolean allowEmpty, int exactDateLength) 解析とレンダリングに指定された DateFormat を使用して、新しい CustomDateEditor インスタンスを作成します。 |
修飾子と型 | メソッドと説明 |
---|---|
StringSE | getAsText() 指定された DateFormat を使用して、日付を文字列としてフォーマットします。 |
void | setAsText(StringSE text) 指定された DateFormat を使用して、指定されたテキストから日付を解析します。 |
addPropertyChangeListenerSE, firePropertyChangeSE, getCustomEditorSE, getJavaInitializationStringSE, getSourceSE, getTagsSE, getValueSE, isPaintableSE, paintValueSE, removePropertyChangeListenerSE, setSourceSE, setValueSE, supportsCustomEditorSE
cloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSE
public CustomDateEditor(DateFormatSE dateFormat, boolean allowEmpty)
"allowEmpty" パラメーターは、解析に空の文字列を許可するかどうか、つまり null 値として解釈されるかどうかを示します。そうでない場合は、IllegalArgumentException がスローされます。
dateFormat
- 解析とレンダリングに使用する DateFormatallowEmpty
- 空の文字列を許可する場合 public CustomDateEditor(DateFormatSE dateFormat, boolean allowEmpty, int exactDateLength)
"allowEmpty" パラメーターは、解析に空の文字列を許可するかどうか、つまり null 値として解釈されるかどうかを示します。そうでない場合は、IllegalArgumentException がスローされます。
"exactDateLength" パラメーターは、ストリングが指定された長さに正確に一致しない場合、IllegalArgumentException がスローされることを示しています。SimpleDateFormat は、setLenient(false)
を使用しても、年の部分の厳密な解析を強制しないため、これは便利です。"exactDateLength" を指定しない場合、"01/01/05" は "01/01/0005" に解析されます。ただし、"exactDateLength" が指定されている場合でも、日または月の部分にゼロを追加すると、年の部分が短くなる可能性があるため、これを、目的の日付形式に近づけるもう 1 つのアサーションと見なしてください。
dateFormat
- 解析とレンダリングに使用する DateFormatallowEmpty
- 空の文字列を許可する場合 exactDateLength
- 日付文字列の正確な予想長 public void setAsText(@Nullable StringSE text) throws IllegalArgumentExceptionSE
PropertyEditorSE
の setAsTextSE
PropertyEditorSupportSE
の setAsTextSE
IllegalArgumentExceptionSE
public StringSE getAsText()
PropertyEditorSE
の getAsTextSE
PropertyEditorSupportSE
の getAsTextSE