webwork/src/main/webwork/util/editor DateEditor.java,1.1,1.2
[email protected] Sat, 29 Jun 2002 18:28:28 -0700
| Newsgroups | gmane.comp.java.webwork.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/webwork/webwork/src/main/webwork/util/editor
In directory usw-pr-cvs1:/tmp/cvs-serv15603
Modified Files:
DateEditor.java
Log Message:
added getAsText()
Index: DateEditor.java
===================================================================
RCS file: /cvsroot/webwork/webwork/src/main/webwork/util/editor/DateEditor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- DateEditor.java 24 Apr 2002 20:22:24 -0000 1.1
+++ DateEditor.java 30 Jun 2002 01:28:26 -0000 1.2
@@ -12,6 +12,7 @@
import java.text.DateFormat;
import java.util.Locale;
+import java.util.Date;
/**
* @see java.beans.PropertyEditorSupport
@@ -38,5 +39,28 @@
throw new IllegalArgumentException("Unable to set value for " + txt);
}
}
+
+ public String getAsText()
+ {
+ return value == null ? "" : formatDate(value);
+ }
+
+ private static String formatDate(Object obj) {
+ try {
+ DateFormatter formatter = new DateFormatter();
+ formatter.setDate((Date)obj);
+
+ try {
+ formatter.setFormat(DateFormat.getDateInstance(DateFormat.SHORT,
+ ActionContext.getContext().getLocale()));
+ } catch (Exception e) {
+ //ignore, use default parser
+ }
+ return formatter.getFormattedDate();
+ } catch(Exception e) {
+ return "";
+ }
+ }
+
}
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
No, I will not fix your computer.
http://thinkgeek.com/sf