You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2012/11/08 20:55:55 UTC
[2/5] git commit: Re-code rendering of the DateField component -
remove the "core-datefield" JavaScriptStack - be explicit about the asset
root,
to avoid problems when resolving assets from @Import - clean up the markup of
the DateFieldDemo page
Re-code rendering of the DateField component
- remove the "core-datefield" JavaScriptStack
- be explicit about the asset root, to avoid problems when resolving assets from @Import
- clean up the markup of the DateFieldDemo page
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/46dcb0fe
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/46dcb0fe
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/46dcb0fe
Branch: refs/heads/5.4-js-rewrite
Commit: 46dcb0fef2ddcb3e00a42ee1af0a65a696973dbd
Parents: 0e94d06
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Thu Nov 8 11:54:58 2012 -0800
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Thu Nov 8 11:54:58 2012 -0800
----------------------------------------------------------------------
.../tapestry5/corelib/components/DateField.java | 63 +++++---
.../services/javascript/DateFieldStack.java | 122 ---------------
.../apache/tapestry5/services/TapestryModule.java | 2 +-
.../services/javascript/JavaScriptModule.java | 3 +-
.../tapestry5/corelib/components/datefield.gif | Bin 127 -> 0 bytes
tapestry-core/src/test/app1/DateFieldDemo.tml | 69 +++++----
6 files changed, 84 insertions(+), 175 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/46dcb0fe/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
index adcd343..5fdaafa 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/DateField.java
@@ -25,6 +25,7 @@ import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.ComponentDefaultProvider;
+import org.apache.tapestry5.services.compatibility.DeprecationWarning;
import java.text.DateFormat;
import java.text.ParseException;
@@ -36,7 +37,7 @@ import java.util.Locale;
* A component used to collect a provided date from the user using a client-side JavaScript calendar. Non-JavaScript
* clients can simply type into a text field.
* <p/>
- * One wierd aspect here is that, because client-side JavaScript formatting and parsing is so limited, we (currently)
+ * One 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). Weird and inefficient, but easier than writing client-side JavaScript for that purpose.
* <p/>
@@ -48,7 +49,7 @@ import java.util.Locale;
* @see TextField
*/
// TODO: More testing; see https://issues.apache.org/jira/browse/TAPESTRY-1844
-@Import(stack = "core-datefield")
+@Import(library = "${tapestry.datepicker}/js/datepicker.js", stylesheet = "${tapestry.datepicker}/css/datepicker.css")
@Events(EventConstants.VALIDATE)
public class DateField extends AbstractField
{
@@ -81,7 +82,12 @@ public class DateField extends AbstractField
@SuppressWarnings("unchecked")
private FieldValidator<Object> validate;
- @Parameter(defaultPrefix = BindingConstants.ASSET, value = "datefield.gif")
+ /**
+ * Icon used for the date field trigger button. This was used in Tapestry 5.3 and earlier and is now ignored.
+ *
+ * @deprecated Deprecated in 5.4 with no replacement. The component leverages the Twitter Bootstrap glyphicons support.
+ */
+ @Parameter(defaultPrefix = BindingConstants.ASSET)
private Asset icon;
/**
@@ -96,11 +102,19 @@ public class DateField extends AbstractField
@Inject
private Locale locale;
+ @Inject
+ private DeprecationWarning deprecationWarning;
+
private static final String RESULT = "result";
private static final String ERROR = "error";
private static final String INPUT_PARAMETER = "input";
+ void pageLoaded()
+ {
+ deprecationWarning.ignoredComponentParameters(resources, "icon");
+ }
+
DateFormat defaultFormat()
{
DateFormat shortDateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
@@ -181,15 +195,28 @@ public class DateField extends AbstractField
String value = validationTracker.getInput(this);
if (value == null)
+ {
value = formatCurrentValue();
+ }
String clientId = getClientId();
- String triggerId = clientId + "-trigger";
+
+ writer.element("div",
+ "data-component-type", "core/DateField",
+ "data-parse-url", resources.createEventLink("parse").toString(),
+ "data-format-url", resources.createEventLink("format").toString());
+
+ if (!hideTextField)
+ {
+ writer.attributes("class", "input-append");
+ }
writer.element("input",
"type", hideTextField ? "hidden" : "text",
+ "class", "input-small",
+
"name", getControlName(),
"id", clientId,
@@ -210,26 +237,24 @@ public class DateField extends AbstractField
writer.end();
- // Now the trigger icon.
-
- writer.element("img",
-
- "id", triggerId,
-
- "class", "t-calendar-trigger",
-
- "src", icon.toClientURL(),
+ writer.element("button",
+ "class", "btn",
"alt", "[Show]");
- writer.end(); // img
+ writer.element("i", "class", "icon-calendar");
+ writer.end();
+ writer.end();
- JSONObject spec = new JSONObject();
- spec.put("field", clientId);
- spec.put("parseURL", resources.createEventLink("parse").toURI());
- spec.put("formatURL", resources.createEventLink("format").toURI());
+ writer.end(); // outer div
- javaScriptSupport.addInitializerCall("dateField", spec);
+// JSONObject spec = new JSONObject();
+//
+// spec.put("field", clientId);
+// spec.put("parseURL", resources.createEventLink("parse").toURI());
+// spec.put("formatURL", resources.createEventLink("format").toURI());
+//
+// javaScriptSupport.addInitializerCall("dateField", spec);
}
private void writeDisabled(MarkupWriter writer)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/46dcb0fe/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
deleted file mode 100644
index 1546b72..0000000
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/javascript/DateFieldStack.java
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2010, 2011 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.internal.services.javascript;
-
-import java.text.DateFormatSymbols;
-import java.util.Calendar;
-import java.util.Collections;
-import java.util.List;
-import java.util.Locale;
-
-import org.apache.tapestry5.Asset;
-import org.apache.tapestry5.SymbolConstants;
-import org.apache.tapestry5.func.F;
-import org.apache.tapestry5.func.Mapper;
-import org.apache.tapestry5.internal.TapestryInternalUtils;
-import org.apache.tapestry5.ioc.annotations.Symbol;
-import org.apache.tapestry5.ioc.services.ThreadLocale;
-import org.apache.tapestry5.json.JSONArray;
-import org.apache.tapestry5.json.JSONObject;
-import org.apache.tapestry5.services.AssetSource;
-import org.apache.tapestry5.services.javascript.JavaScriptStack;
-import org.apache.tapestry5.services.javascript.StylesheetLink;
-
-public class DateFieldStack implements JavaScriptStack
-{
- private final ThreadLocale threadLocale;
-
- private final boolean compactJSON;
-
- private final List<Asset> javaScriptStack;
-
- private final List<StylesheetLink> stylesheetStack;
-
- public DateFieldStack(ThreadLocale threadLocale, @Symbol(SymbolConstants.COMPACT_JSON)
- boolean compactJSON, final AssetSource assetSource)
- {
- this.threadLocale = threadLocale;
- this.compactJSON = compactJSON;
-
- Mapper<String, Asset> pathToAsset = new Mapper<String, Asset>()
- {
- public Asset map(String path)
- {
- return assetSource.getExpandedAsset(path);
- }
- };
-
- Mapper<String, StylesheetLink> pathToStylesheetLink = F.combine(pathToAsset,
- TapestryInternalUtils.assetToStylesheetLink);
-
- javaScriptStack = F
- .flow("${tapestry.datepicker}/js/datepicker.js", "org/apache/tapestry5/corelib/components/datefield.js")
- .map(pathToAsset).toList();
-
- stylesheetStack = F.flow("${tapestry.datepicker}/css/datepicker.css").map(pathToStylesheetLink).toList();
- }
-
- public String getInitialization()
- {
- Locale locale = threadLocale.getLocale();
-
- JSONObject spec = new JSONObject();
-
- DateFormatSymbols symbols = new DateFormatSymbols(locale);
-
- spec.put("months", new JSONArray((Object[])symbols.getMonths()));
-
- StringBuilder days = new StringBuilder();
-
- String[] weekdays = symbols.getWeekdays();
-
- 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?
-
- return String.format("Tapestry.DateField.initLocalization(%s);", spec.toString(compactJSON));
- }
-
- public List<Asset> getJavaScriptLibraries()
- {
- return javaScriptStack;
- }
-
- public List<StylesheetLink> getStylesheets()
- {
- return stylesheetStack;
- }
-
- public List<String> getStacks()
- {
- return Collections.emptyList();
- }
-}
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/46dcb0fe/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
index 7ac90be..0c9a69a 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
@@ -2131,7 +2131,7 @@ public final class TapestryModule
// files deleted between scriptaculous releases to be accidentally left lying around).
// There's also a ClasspathAliasManager contribution based on the path.
- configuration.add("tapestry.asset.root", "META-INF/assets/tapestry5");
+ configuration.add("tapestry.asset.root", "classpath:/META-INF/assets/tapestry5");
configuration.add(SymbolConstants.SCRIPTACULOUS, "${tapestry.asset.root}/scriptaculous_1_9_0");
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/46dcb0fe/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
index a5ef4b0..5d1694c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptModule.java
@@ -65,7 +65,7 @@ public class JavaScriptModule
}
/**
- * Contributes the "core" and "core-datefield" {@link JavaScriptStack}s
+ * Contributes the "core" {@link JavaScriptStack}s
*
* @since 5.2.0
*/
@@ -73,7 +73,6 @@ public class JavaScriptModule
public static void provideBuiltinJavaScriptStacks(MappedConfiguration<String, JavaScriptStack> configuration, @Core JavaScriptStack coreStack)
{
configuration.add(InternalConstants.CORE_STACK_NAME, coreStack);
- configuration.addInstance("core-datefield", DateFieldStack.class);
}
@Contribute(JavaScriptStack.class)
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/46dcb0fe/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.gif
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.gif b/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.gif
deleted file mode 100644
index 8526cf5..0000000
Binary files a/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/datefield.gif and /dev/null differ
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/46dcb0fe/tapestry-core/src/test/app1/DateFieldDemo.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/DateFieldDemo.tml b/tapestry-core/src/test/app1/DateFieldDemo.tml
index f57945f..e52aa64 100644
--- a/tapestry-core/src/test/app1/DateFieldDemo.tml
+++ b/tapestry-core/src/test/app1/DateFieldDemo.tml
@@ -1,47 +1,54 @@
<html t:type="Border"
- xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+ xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd">
- <h1>DateField Demo</h1>
+<h1>DateField Demo</h1>
- <t:form>
- <t:errors/>
+<t:form>
+ <t:errors/>
- <div class="t-beaneditor">
+ <div class="control-group">
+ <t:label for="birthday"/>
+ <div class="controls">
+ <t:datefield format="d MMM yyyy" hidetextfield="true" t:id="birthday"/>
+ </div>
+ </div>
+
+ <div class="control-group">
+ <t:label for="asteroidImpact"/>
+ <div class="controls">
+ <t:datefield t:id="asteroidImpact"/>
+ </div>
+ </div>
- <div class="t-beaneditor-row">
- <t:label for="birthday"/>
- <t:datefield format="d MMM yyyy" hidetextfield="true" t:id="birthday"/>
- </div>
- <div class="t-beaneditor-row">
- <t:label for="asteroidImpact"/>
- <t:datefield t:id="asteroidImpact"/>
- </div>
+ <div class="form-actions">
+ <input type="submit" value="Go" class="btn btn-primary"/>
+ </div>
+</t:form>
- <div class="t-beaneditor-row">
- <input type="submit" value="Go"/>
- </div>
+<div class="btn-toolbar btn-group">
- </div>
- </t:form>
+ <t:actionlink class="btn" t:id="clear">clear</t:actionlink>
+ <t:actionlink class="btn" t:id="english">english</t:actionlink>
+ <t:actionlink class="btn" t:id="french">french</t:actionlink>
+</div>
+
+<t:if test="birthday">
+ <hr/>
<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>
+ Birthday: [
+ <t:output value="birthday" format="dateFormat"/>
+ ]
</p>
- <t:if test="birthday">
- <hr/>
- <p>
- Birthday: [<t:output value="birthday" format="dateFormat"/>]
- </p>
-
- <p>
- Impact: [<t:output value="asteroidImpact" format="dateFormat"/>]
- </p>
- </t:if>
+ <p>
+ Impact: [
+ <t:output value="asteroidImpact" format="dateFormat"/>
+ ]
+ </p>
+</t:if>
</html>