public class CustomDateEditor extends PropertyEditorSupportSE
java.text.DateFormat をサポートする java.util.Date のプロパティエディター。これは、システム PropertyEditor として使用するためのものではなく、カスタムコントローラーコード内のロケール固有の日付エディターとして使用して、ユーザーが入力した数値文字列を Bean の Date プロパティに解析し、UI フォームにレンダリングします。
Web MVC コードでは、このエディターは通常 binder.registerCustomEditor に登録されます。
DateSE, DateFormatSE, 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, supportsCustomEditorSEcloneSE, equalsSE, finalizeSE, getClassSE, hashCodeSE, notifySE, notifyAllSE, toStringSE, waitSE, waitSE, waitSEpublic 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(StringSE text) throws IllegalArgumentExceptionSE
PropertyEditorSE の setAsTextSE PropertyEditorSupportSE の setAsTextSE IllegalArgumentExceptionSEpublic StringSE getAsText()
PropertyEditorSE の getAsTextSE PropertyEditorSupportSE の getAsTextSE