You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by gc...@apache.org on 2009/12/03 20:47:11 UTC
svn commit: r886896 - in /myfaces/trinidad/branches/1.2.12.2-branch:
trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js
Author: gcrawford
Date: Thu Dec 3 19:47:11 2009
New Revision: 886896
URL: http://svn.apache.org/viewvc?rev=886896&view=rev
Log:
TRINIDAD-1634 tr:convertDateTime error handling can be improved to distinguish invalid date from invalid date format
Modified:
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts?rev=886896&r1=886895&r2=886896&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-api/src/main/xrts/org/apache/myfaces/trinidad/resource/MessageBundle.xrts Thu Dec 3 19:47:11 2009
@@ -312,7 +312,6 @@
<!-- {1} value entered by the user -->
<!-- {2} an example of the format the converter is expecting -->
<resource key="org.apache.myfaces.trinidad.convert.DateTimeConverter.CONVERT_DATE">The date is not in the correct format.</resource>
-
<resource key="org.apache.myfaces.trinidad.convert.DateTimeConverter.CONVERT_DATE_detail">Enter a date in the same format as this example: {2}</resource>
<!-- {0} the label that identifies the component -->
@@ -329,6 +328,12 @@
<resource key="org.apache.myfaces.trinidad.convert.DateTimeConverter.CONVERT_BOTH_detail">Enter a date and time in the same format as this example: {2}</resource>
+ <!-- {0} the label that identifies the component -->
+ <!-- {1} value entered by the user -->
+ <resource key="org.apache.myfaces.trinidad.convert.DateTimeConverter.CONVERT_DATE_INVALID_DATE">The date or time entered is not valid.</resource>
+ <resource key="org.apache.myfaces.trinidad.convert.DateTimeConverter.CONVERT_DATE_INVALID_DATE_detail">Enter a valid date or time. </resource>
+
+
<!-- {0} the label that identifies the component -->
<!-- {1} value entered by the user -->
<!-- {2} the pattern the converter is expecting -->
Modified: myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js
URL: http://svn.apache.org/viewvc/myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js?rev=886896&r1=886895&r2=886896&view=diff
==============================================================================
--- myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js (original)
+++ myfaces/trinidad/branches/1.2.12.2-branch/trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/DateFormat.js Thu Dec 3 19:47:11 2009
@@ -1170,11 +1170,11 @@
var pattern = this._pattern;
- var facesMessage;
+ var invalidFormatMsg;
var key = "org.apache.myfaces.trinidad.convert.DateTimeConverter.CONVERT_"+this._type;
if(this._messages && this._messages["detail"])
{
- facesMessage = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
+ invalidFormatMsg = _createCustomFacesMessage(TrMessageFactory.getSummaryString(key),
this._messages["detail"],
label,
parseString,
@@ -1182,17 +1182,23 @@
}
else
{
- facesMessage = _createFacesMessage( key,
+ invalidFormatMsg = _createFacesMessage( key,
label,
parseString,
this._exampleString);
}
+
+ var invalidDateMsg = _createFacesMessage ("org.apache.myfaces.trinidad.convert.DateTimeConverter.CONVERT_DATE_INVALID_DATE",
+ label,
+ parseString);
+
if (typeof pattern == "string")
{
return this._simpleDateParseImpl(parseString,
pattern,
this._localeSymbols,
- facesMessage);
+ invalidFormatMsg,
+ invalidDateMsg);
}
else
{
@@ -1203,11 +1209,17 @@
var date = this._simpleDateParseImpl(parseString,
pattern[i],
this._localeSymbols,
- facesMessage);
+ invalidFormatMsg,
+ invalidDateMsg);
return date;
}
catch (e)
{
+ // Trinidad-1634: If the format is valid, but the date is invalid,
+ // return that error instead of trying other formats.
+ if (e.isDateInvalid)
+ throw e;
+
// if we're not on the last pattern try the next one,
// but if we're on the last pattern, throw the exception
if ( i == pattern.length-1 )
@@ -1337,7 +1349,8 @@
parseString,
parsePattern,
localeSymbols,
- msg)
+ invalidFormatMsg,
+ invalidDateMsg)
{
// When a pattern (e.g. dd.MM.yyyy HH:mm' Uhr ') requires a whitespace
// at the end, we should honor that. As the JSF spec (see http://bit.ly/kTelf)
@@ -1362,7 +1375,6 @@
parseContext.parsedDate = null;
parseContext.hourOffset = null;
parseContext.minOffset = null;
- parseContext.parseException = new TrConverterException( msg);
var parsedTime = new Date(0);
parsedTime.setDate(1);
@@ -1376,6 +1388,7 @@
{
if (parseString.length != parseContext.currIndex)
{
+ parseContext.parseException = new TrConverterException (invalidFormatMsg);
throw parseContext.parseException;
}
@@ -1445,6 +1458,10 @@
// now we check for strictness
if (!_isStrict(parseContext, parsedTime))
{
+ // Trinidad-1634: If the format is correct, but the date doesn't
+ // match, throw a different error.
+ parseContext.parseException = new TrConverterException (invalidDateMsg);
+ parseContext.parseException.isDateInvalid = true;
throw parseContext.parseException;
}
@@ -1460,6 +1477,7 @@
else
{
// failure
- throw parseContext.parseException;
+ parseContext.parseException = new TrConverterException (invalidFormatMsg);
+ throw parseContext.parseException;
}
}