You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2008/10/14 02:30:04 UTC

svn commit: r704289 - in /tapestry/tapestry5/trunk/tapestry-core/src/main: java/org/apache/tapestry5/corelib/components/DateField.java resources/org/apache/tapestry5/corelib/components/datefield.js

Author: hlship
Date: Mon Oct 13 17:30:03 2008
New Revision: 704289

URL: http://svn.apache.org/viewvc?rev=704289&view=rev
Log:
TAP5-224: DateField shows day abbreviation labels in wrong order for some non-english locales

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=704289&r1=704288&r2=704289&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 Mon Oct 13 17:30:03 2008
@@ -43,6 +43,9 @@
  * One wierd aspect here is that, because client-side JavaScript formatting and parsing is so limited, we (currently)
  * use Ajax to send the user's input to the server for parsing (before raising the popup) and formatting (after closing
  * the popup).  Wierd and inefficient, but easier than writing client-side JavaScript for that purpose.
+ * <p/>
+ * Tapestry's DateField component is a wrapper around <a href="http://webfx.eae.net/dhtml/datepicker/datepicker.html">WebFX
+ * DatePicker</a>.
  */
 // TODO: More testing; see https://issues.apache.org/jira/browse/TAPESTRY-1844
 @IncludeStylesheet("${tapestry.datepicker}/css/datepicker.css")
@@ -52,7 +55,7 @@
 public class DateField extends AbstractField
 {
     /**
-     * The value parameter of a DateField must be a {@link Date}.
+     * The value parameter of a DateField must be a {@link java.util.Date}.
      */
     @Parameter(required = true, principal = true, autoconnect = true)
     private Date value;
@@ -256,13 +259,25 @@
 
             String[] weekdays = symbols.getWeekdays();
 
-            for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++)
+            Calendar c = Calendar.getInstance(locale);
+
+            int firstDay = c.getFirstDayOfWeek();
+
+            // DatePicker needs them in order from monday to sunday.
+
+            for (int i = Calendar.MONDAY; i <= Calendar.SATURDAY; i++)
             {
                 days.append(weekdays[i].substring(0, 1));
             }
 
+            days.append(weekdays[Calendar.SUNDAY].substring(0, 1));
+
             spec.put("days", days.toString().toLowerCase(locale));
 
+            // DatePicker expects 0 to be monday. Calendar defines SUNDAY as 1, MONDAY as 2, etc.
+
+            spec.put("firstDay", firstDay == Calendar.SUNDAY ? 6 : firstDay - 2);
+
             // TODO: Skip localization if locale is English?
 
             setup.put("localization", spec);

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=704289&r1=704288&r2=704289&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 Mon Oct 13 17:30:03 2008
@@ -31,6 +31,8 @@
         {
             DatePicker.months = spec.localization.months;
             DatePicker.days = spec.localization.days.toArray();
+
+            Tapestry.DateField.prototype.firstDay = spec.localization.firstDay;
         }
     },
 
@@ -116,6 +118,8 @@
     {
         this.datePicker = new DatePicker();
 
+        this.datePicker.setFirstWeekDay(this.firstDay);
+
         this.popup = $(this.datePicker.create());
 
         this.field.insert({ after : this.popup });