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/09/05 00:25:36 UTC
svn commit: r692278 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/corelib/components/
main/java/org/apache/tapestry5/json/ main/java/org/apache/tapestry5/services/
main/resources/org/apache/tapestry5/corelib/component...
Author: hlship
Date: Thu Sep 4 15:25:29 2008
New Revision: 692278
URL: http://svn.apache.org/viewvc?rev=692278&view=rev
Log:
TAPESTRY-2617: DateField component should localize the month names and day name abbreviations shown in the client web browser
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/json/JSONArray.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HiddenFieldLocationRules.java
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.js
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DateFieldDemo.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java
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=692278&r1=692277&r2=692278&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 Sep 4 15:25:29 2008
@@ -22,14 +22,17 @@
import org.apache.tapestry5.corelib.base.AbstractField;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.json.JSONArray;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.ComponentDefaultProvider;
import org.apache.tapestry5.services.FieldValidatorDefaultSource;
import org.apache.tapestry5.services.Request;
import java.text.DateFormat;
+import java.text.DateFormatSymbols;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
@@ -55,6 +58,12 @@
private Date value;
/**
+ * Request attribute set to true if localization for the client-side DatePicker has been configured. Used to ensure
+ * that this only occurs once, regardless of how many DateFields are on the page.
+ */
+ static final String LOCALIZATION_CONFIGURED_FLAG = "tapestry.DateField.localization-configured";
+
+ /**
* The format used to format <em>and parse</em> dates. This is typically specified as a string which is coerced to a
* DateFormat. You should be aware that using a date format with a two digit year is problematic: Java (not
* Tapestry) may get confused about the century.
@@ -104,6 +113,7 @@
private static final String ERROR = "error";
private static final String INPUT_PARAMETER = "input";
+
DateFormat defaultFormat()
{
DateFormat shortDateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
@@ -227,6 +237,32 @@
setup.put("parseURL", resources.createEventLink("parse").toAbsoluteURI());
setup.put("formatURL", resources.createEventLink("format").toAbsoluteURI());
+ if (request.getAttribute(LOCALIZATION_CONFIGURED_FLAG) == null)
+ {
+ JSONObject spec = new JSONObject();
+
+ DateFormatSymbols symbols = new DateFormatSymbols(locale);
+
+ spec.put("months", new JSONArray(symbols.getMonths()));
+
+ StringBuilder days = new StringBuilder();
+
+ String[] weekdays = symbols.getWeekdays();
+
+ for (int i = Calendar.SUNDAY; i <= Calendar.SATURDAY; i++)
+ {
+ days.append(weekdays[i].substring(0, 1));
+ }
+
+ spec.put("days", days.toString().toLowerCase(locale));
+
+ // TODO: Skip localization if locale is English?
+
+ setup.put("localization", spec);
+
+ request.setAttribute(LOCALIZATION_CONFIGURED_FLAG, true);
+ }
+
support.addInit("dateField", setup);
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/json/JSONArray.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/json/JSONArray.java?rev=692278&r1=692277&r2=692278&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/json/JSONArray.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/json/JSONArray.java Thu Sep 4 15:25:29 2008
@@ -1,4 +1,4 @@
-// Copyright 2007 The Apache Software Foundation
+// Copyright 2007, 2008 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -95,6 +95,11 @@
parse(tokener);
}
+ public JSONArray(Object... values)
+ {
+ for (Object value : values) put(value);
+ }
+
/**
* Construct a JSONArray from a JSONTokener.
*
@@ -386,7 +391,6 @@
while (index != length()) list.add(JSONObject.NULL);
list.add(value);
-
}
return this;
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HiddenFieldLocationRules.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HiddenFieldLocationRules.java?rev=692278&r1=692277&r2=692278&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HiddenFieldLocationRules.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/HiddenFieldLocationRules.java Thu Sep 4 15:25:29 2008
@@ -1,3 +1,17 @@
+// Copyright 2008 The Apache Software Foundation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
package org.apache.tapestry5.services;
import org.apache.tapestry5.dom.Element;
@@ -5,7 +19,6 @@
/**
* Provides some assistance in determining <em>where</em> to place a hidden field based on standard (X)HTML elements.
* <p/>
- * <p/>
* The service works based on a mapped service contribution; keys are the element names, values area {@link
* org.apache.tapestry5.services.RelativeElementPosition}.
*/
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=692278&r1=692277&r2=692278&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 Sep 4 15:25:29 2008
@@ -26,6 +26,12 @@
this.trigger.observe("click", this.triggerClicked.bind(this));
this.popup = null;
+
+ if (spec.localization)
+ {
+ DatePicker.months = spec.localization.months;
+ DatePicker.days = spec.localization.days.toArray();
+ }
},
triggerClicked : function()
@@ -184,6 +190,8 @@
}
});
+Tapestry.DateField.localized = false;
+
Tapestry.Initializer.dateField = function(spec)
{
new Tapestry.DateField(spec);
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DateFieldDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DateFieldDemo.tml?rev=692278&r1=692277&r2=692278&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DateFieldDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DateFieldDemo.tml Thu Sep 4 15:25:29 2008
@@ -26,6 +26,12 @@
</div>
</t:form>
+ <p>
+ <t:actionlink t:id="clear">clear</t:actionlink>
+ <t:actionlink t:id="english">english</t:actionlink>
+ <t:actionlink t:id="french">french</t:actionlink>
+ </p>
+
<t:if test="birthday">
<hr/>
<p>
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=692278&r1=692277&r2=692278&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java Thu Sep 4 15:25:29 2008
@@ -1173,7 +1173,7 @@
@Test
public void basic_datefield()
{
- start("DateField Demo");
+ start("DateField Demo", "clear", "english");
// TODO: Check to see if we need to explicitly set the locale for this test to work properly.
@@ -1187,6 +1187,17 @@
assertFieldValue("birthday", "24 Dec 1966");
assertFieldValue("asteroidImpact", "5/28/2046");
+
+ clickAndWait("link=french");
+
+ click("birthday:trigger");
+
+ waitForCondition("selenium.browserbot.getCurrentWindow().$$('DIV.datePicker').first().isDeepVisible() == true",
+ PAGE_LOAD_TIMEOUT);
+
+ assertText("//A[@class='topLabel']", "1966 dcembre");
+
+ clickAndWait("link=english");
}
/**
@@ -2200,7 +2211,7 @@
click(SUBMIT);
- waitForElementToAppear("ammount:errorpopup");
+ waitForElementToAppear("amount:errorpopup");
waitForElementToAppear("quantity:errorpopup");
assertText("//div[@id='amount:errorpopup']/span", "You must provide a numeric value for Amount.");
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java?rev=692278&r1=692277&r2=692278&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DateFieldDemo.java Thu Sep 4 15:25:29 2008
@@ -16,10 +16,13 @@
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.beaneditor.Validate;
+import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.services.PersistentLocale;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.Locale;
public class DateFieldDemo
{
@@ -29,6 +32,9 @@
@Persist
private Date asteroidImpact;
+ @Inject
+ private PersistentLocale persistentLocale;
+
@Validate("required")
public Date getBirthday()
{
@@ -55,4 +61,14 @@
{
this.asteroidImpact = asteroidImpact;
}
+
+ void onActionFromClear()
+ {
+ birthday = null;
+ asteroidImpact = null;
+ }
+
+ void onActionFromEnglish() { persistentLocale.set(Locale.ENGLISH); }
+
+ void onActionFromFrench() { persistentLocale.set(Locale.FRENCH); }
}