You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2022/11/16 10:25:23 UTC
[myfaces-tobago] branch main updated: fix(date): type=time/datetime-local
This is an automated email from the ASF dual-hosted git repository.
hnoeth pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/main by this push:
new 8e723cca7e fix(date): type=time/datetime-local
8e723cca7e is described below
commit 8e723cca7e823cc86c99b0a7d751ccf5642b9493
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Thu Nov 10 17:03:18 2022 +0100
fix(date): type=time/datetime-local
* add tests
* fix: type=time for java.util.Date
* fix: type=datetime-local for java.util.Date
Issue: TOBAGO-2168
---
.../internal/renderkit/renderer/DateRenderer.java | 23 +++++++-
.../tobago/example/demo/DateTestController.java | 10 ++++
.../webapp/content/900-test/1100-date/Date.test.js | 66 +++++++++++++++++++++-
.../webapp/content/900-test/1100-date/Date.xhtml | 43 ++++++++++++++
4 files changed, 140 insertions(+), 2 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/DateRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/DateRenderer.java
index 2ba9c5a906..db6064c0bb 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/DateRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/DateRenderer.java
@@ -257,7 +257,28 @@ public class DateRenderer<T extends AbstractUIDate> extends MessageLayoutRendere
dateTimeConverter.setPattern(DateType.PATTERN_DATE);
} else if (estimatedType.isAssignableFrom(Date.class)) {
dateTimeConverter.setType("date");
- dateTimeConverter.setPattern(DateType.PATTERN_DATE);
+ final DateType type = component.getType();
+ if (DateType.DATETIME_LOCAL.equals(type)) {
+ final Double step = component.getStep();
+ if (step == null || step >= 60) {
+ dateTimeConverter.setPattern(DateType.PATTERN_DATETIME_LOCAL);
+ } else if (step >= 1) {
+ dateTimeConverter.setPattern(DateType.PATTERN_DATETIME_LOCAL_SECONDS);
+ } else {
+ dateTimeConverter.setPattern(DateType.PATTERN_DATETIME_LOCAL_MILLIS);
+ }
+ } else if (DateType.TIME.equals(type)) {
+ final Double step = component.getStep();
+ if (step == null || step >= 60) {
+ dateTimeConverter.setPattern(DateType.PATTERN_TIME);
+ } else if (step >= 1) {
+ dateTimeConverter.setPattern(DateType.PATTERN_TIME_SECONDS);
+ } else {
+ dateTimeConverter.setPattern(DateType.PATTERN_TIME_MILLIS);
+ }
+ } else {
+ dateTimeConverter.setPattern(DateType.PATTERN_DATE);
+ }
} else if (estimatedType.isAssignableFrom(Number.class)) {
LOG.error("date");
dateTimeConverter.setType("date");
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateTestController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateTestController.java
index 22dda64490..6156e386f0 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateTestController.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateTestController.java
@@ -24,6 +24,7 @@ import jakarta.enterprise.context.RequestScoped;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
+import java.util.Date;
@RequestScoped
@Named
@@ -39,6 +40,7 @@ public class DateTestController {
private LocalDate month;
private LocalDate week;
private Long longValue;
+ private Date dateTime;
public LocalDate getLocalDate() {
return localDate;
@@ -119,4 +121,12 @@ public class DateTestController {
public void setLongValue(Long longValue) {
this.longValue = longValue;
}
+
+ public Date getDateTime() {
+ return dateTime;
+ }
+
+ public void setDateTime(Date dateTime) {
+ this.dateTime = dateTime;
+ }
}
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/1100-date/Date.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/1100-date/Date.test.js
index 625466b257..8efb5e0176 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/1100-date/Date.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/1100-date/Date.test.js
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-import {querySelectorFn} from "/script/tobago-test.js";
+import {elementByIdFn, querySelectorFn} from "/script/tobago-test.js";
import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
it("#1 model=java.time.LocalDate", function (done) {
@@ -122,3 +122,67 @@ it("#7 model=java.time.LocalDateTime step=0.001", function (done) {
test.do(() => expect(outPutFn().textContent === time));
test.start();
});
+
+it("#11 model=java.util.Date type=time", function (done) {
+ const dateFn = elementByIdFn("page:mainForm:dateTimeForm:dateTime::field");
+ const outputFn = querySelectorFn("#page\\:mainForm\\:dateTimeForm\\:dateTimeOutput .form-control-plaintext");
+ const submitButtonFn = elementByIdFn("page:mainForm:dateTimeForm:dateTimeButton");
+ const resetButtonFn = elementByIdFn("page:mainForm:resetButtonFrom:resetButton");
+
+ const time = "12:34";
+
+ const test = new JasmineTestTool(done);
+ test.setup(() => outputFn().textContent === "", null, "click", resetButtonFn);
+ test.do(() => dateFn().value = time);
+ test.event("click", submitButtonFn, () => outputFn().textContent === time);
+ test.do(() => expect(outputFn().textContent === time));
+ test.start();
+});
+
+it("#12 model=java.util.Date type=time step=1", function (done) {
+ const dateFn = elementByIdFn("page:mainForm:dateTimeStep1Form:dateTimeStep1::field");
+ const outputFn = querySelectorFn("#page\\:mainForm\\:dateTimeStep1Form\\:dateTimeStep1Output .form-control-plaintext");
+ const submitButtonFn = elementByIdFn("page:mainForm:dateTimeStep1Form:dateTimeStep1Button");
+ const resetButtonFn = elementByIdFn("page:mainForm:resetButtonFrom:resetButton");
+
+ const time = "12:34:56";
+
+ const test = new JasmineTestTool(done);
+ test.setup(() => outputFn().textContent === "", null, "click", resetButtonFn);
+ test.do(() => dateFn().value = time);
+ test.event("click", submitButtonFn, () => outputFn().textContent === time);
+ test.do(() => expect(outputFn().textContent === time));
+ test.start();
+});
+
+it("#13 model=java.util.Date type=datetime-local", function (done) {
+ const dateFn = elementByIdFn("page:mainForm:dateDateTimeForm:dateDateTime::field");
+ const outputFn = querySelectorFn("#page\\:mainForm\\:dateDateTimeForm\\:dateDateTimeOutput .form-control-plaintext");
+ const submitButtonFn = elementByIdFn("page:mainForm:dateDateTimeForm:dateDateTimeButton");
+ const resetButtonFn = elementByIdFn("page:mainForm:resetButtonFrom:resetButton");
+
+ const time = "2010-05-30T23:45";
+
+ const test = new JasmineTestTool(done);
+ test.setup(() => outputFn().textContent === "", null, "click", resetButtonFn);
+ test.do(() => dateFn().value = time);
+ test.event("click", submitButtonFn, () => outputFn().textContent === time);
+ test.do(() => expect(outputFn().textContent === time));
+ test.start();
+});
+
+it("#14 model=java.util.Date type=datetime-local step=1", function (done) {
+ const dateFn = elementByIdFn("page:mainForm:dateDateTimeStep1Form:dateDateTimeStep1::field");
+ const outputFn = querySelectorFn("#page\\:mainForm\\:dateDateTimeStep1Form\\:dateDateTimeStep1Output .form-control-plaintext");
+ const submitButtonFn = elementByIdFn("page:mainForm:dateDateTimeStep1Form:dateDateTimeStep1Button");
+ const resetButtonFn = elementByIdFn("page:mainForm:resetButtonFrom:resetButton");
+
+ const time = "2010-05-30T23:45:32";
+
+ const test = new JasmineTestTool(done);
+ test.setup(() => outputFn().textContent === "", null, "click", resetButtonFn);
+ test.do(() => dateFn().value = time);
+ test.event("click", submitButtonFn, () => outputFn().textContent === time);
+ test.do(() => expect(outputFn().textContent === time));
+ test.start();
+});
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/1100-date/Date.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/1100-date/Date.xhtml
index 53443dbe85..26f128b46a 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/1100-date/Date.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/900-test/1100-date/Date.xhtml
@@ -133,6 +133,49 @@
<tc:button defaultCommand="true" id="longButton" label="Submit"/>
</tc:box>
</tc:form>
+
+ <tc:form id="dateTimeForm">
+ <tc:box label="#11 model=java.util.Date type=time">
+ <tc:date id="dateTime" type="time" label="Date (time)" value="#{dateTestController.dateTime}" required="true"/>
+ <tc:out id="dateTimeOutput" label="Output" value="#{dateTestController.dateTime}">
+ <f:convertDateTime pattern="HH:mm"/>
+ </tc:out>
+ <tc:button defaultCommand="true" id="dateTimeButton" label="Submit"/>
+ </tc:box>
+ </tc:form>
+
+ <tc:form id="dateTimeStep1Form">
+ <tc:box label="#12 model=java.util.Date type=time step=1">
+ <tc:date id="dateTimeStep1" type="time" step="1" label="Date (time)" value="#{dateTestController.dateTime}"
+ required="true"/>
+ <tc:out id="dateTimeStep1Output" label="Output" value="#{dateTestController.dateTime}">
+ <f:convertDateTime pattern="HH:mm:ss"/>
+ </tc:out>
+ <tc:button defaultCommand="true" id="dateTimeStep1Button" label="Submit"/>
+ </tc:box>
+ </tc:form>
+
+ <tc:form id="dateDateTimeForm">
+ <tc:box label="#13 model=java.util.Date type=datetime-local">
+ <tc:date id="dateDateTime" type="datetime-local" label="Date (datetime-local)"
+ value="#{dateTestController.dateTime}" required="true"/>
+ <tc:out id="dateDateTimeOutput" label="Output" value="#{dateTestController.dateTime}">
+ <f:convertDateTime pattern="yyyy-MM-dd'T'HH:mm"/>
+ </tc:out>
+ <tc:button defaultCommand="true" id="dateDateTimeButton" label="Submit"/>
+ </tc:box>
+ </tc:form>
+
+ <tc:form id="dateDateTimeStep1Form">
+ <tc:box label="#14 model=java.util.Date type=datetime-local step=1">
+ <tc:date id="dateDateTimeStep1" type="datetime-local" step="1" label="Date (datetime-local)"
+ value="#{dateTestController.dateTime}" required="true"/>
+ <tc:out id="dateDateTimeStep1Output" label="Output" value="#{dateTestController.dateTime}">
+ <f:convertDateTime pattern="yyyy-MM-dd'T'HH:mm:ss"/>
+ </tc:out>
+ <tc:button defaultCommand="true" id="dateDateTimeStep1Button" label="Submit"/>
+ </tc:box>
+ </tc:form>
</tc:segmentLayout>
</ui:composition>