Author: hlship
Date: Thu Oct 16 16:20:13 2008
New Revision: 705401
URL: http://svn.apache.org/viewvc?rev=705401&view=rev
Log:
TAP5-225: DateField shows empty selection after first date select
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.js
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java?rev=705401&r1=705400&r2=705401&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
Thu Oct 16 16:20:13 2008
@@ -113,10 +113,6 @@
@Inject
private FieldValidationSupport fieldValidationSupport;
- /**
- * For output, format nicely and unambiguously as four digits.
- */
- private final DateFormat popupFormat = new SimpleDateFormat("MM/dd/yyyy");
private static final String RESULT = "result";
@@ -165,7 +161,7 @@
{
Date date = format.parse(input);
- response.put(RESULT, date.toString());
+ response.put(RESULT, date.getTime());
}
catch (ParseException ex)
{
@@ -176,8 +172,9 @@
}
/**
- * Ajax event handler, used after the popup completes. The client sends
the date, formatted as "MM/dd/yyyy" to the
- * server, which reformats it according to the server side format and
returns the result.
+ * Ajax event handler, used after the client-side popup completes. The
client sends the date, formatted as
+ * milliseconds since the epoch, to the server, which reformats it
according to the server side format and returns
+ * the result.
*/
JSONObject onFormat()
{
@@ -187,11 +184,13 @@
try
{
- Date date = popupFormat.parse(input);
+ long millis = Long.parseLong(input);
+
+ Date date = new Date(millis);
response.put(RESULT, format.format(date));
}
- catch (ParseException ex)
+ catch (NumberFormatException ex)
{
response.put(ERROR, ex.getMessage());
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.js
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.js?rev=705401&r1=705400&r2=705401&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.js
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.js
Thu Oct 16 16:20:13 2008
@@ -70,7 +70,9 @@
var resultHandler = function(result)
{
- var date = new Date(result);
+ var date = new Date();
+
+ date.setTime(result);
this.datePicker.setDate(date);
@@ -128,7 +130,7 @@
this.datePicker.onselect = function()
{
- var input = this.canonicalizeDate(this.datePicker.getDate());
+ var date = this.datePicker.getDate();
var resultHandler = function(result)
{
@@ -147,20 +149,16 @@
this.hidePopup();
};
- this.sendServerRequest(this.formatURL, input, resultHandler,
errorHandler);
- }.bind(this);
- },
+ // If the field is blank, don't bother going to the server to
parse!
- /**
- * Reformats the date into a canoncialized format accepted on the server.
The format
- * is equivalent to M/d/yyyy. This format is used regardless of
localization.
- */
- canonicalizeDate : function(date)
- {
- if (date == null) return "";
+ if (date == null)
+ {
+ resultHandler.call(this, "");
+ return;
+ }
- // Americanized format is simply transfer format. Localization occurs
on the server.
- return (date.getMonth() + 1) + "/" + date.getDate() + "/" +
date.getFullYear();
+ this.sendServerRequest(this.formatURL, date.getTime(),
resultHandler, errorHandler);
+ }.bind(this);
},
positionPopup : function()