You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2021/04/30 08:36:03 UTC

[myfaces-tobago] branch master updated (1492a31 -> fa1ecb7)

This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git.


    from 1492a31  build(deps-dev): bump uglify-js from 3.13.4 to 3.13.5 in /tobago-theme
     new 45b6f80  feat: progress on date input
     new 1891cac  feat: progress on date input
     new fa1ecb7  feat: progress on date input

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../tobago/internal/component/AbstractUIDate.java  |  13 +--
 .../internal/renderkit/renderer/DateRenderer.java  | 116 +++++++++++----------
 .../taglib/component/DateTagDeclaration.java       |  20 ++++
 .../tobago/renderkit/css/CustomClassEditor.java    |   5 -
 .../HtmlInputTypesEditor.java}                     |  12 +--
 .../src/test/resources/renderer/date/dateAuto.html |   1 -
 .../src/test/resources/renderer/date/dateBoth.html |   2 -
 .../src/test/resources/renderer/date/dateDate.html |   1 -
 .../src/test/resources/renderer/date/dateTime.html |   1 -
 .../resources/renderer/date/localDateAuto.html     |   1 -
 .../resources/renderer/date/localDateTimeAuto.html |   2 -
 .../resources/renderer/date/localTimeAuto.html     |   1 -
 .../src/test/resources/renderer/date/minMax.html   |   1 -
 .../test/resources/renderer/date/testLabel.html    |   1 -
 .../resources/renderer/date/testTodayButton.html   |   1 -
 .../src/test/resources/renderer/date/text.html     |   2 -
 .../resources/renderer/date/zonedDateTimeAuto.html |   2 -
 .../tobago/example/demo/DateController.java        |  94 +++++++++++++++++
 .../20-component/010-input/40-date/Date.test.js    |  42 +++-----
 .../20-component/010-input/40-date/Date.xhtml      |  60 +++++++++--
 .../org/apache/myfaces/tobago/apt/component.stg    |   4 +
 21 files changed, 254 insertions(+), 128 deletions(-)
 copy tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/{css/CustomClassEditor.java => html/HtmlInputTypesEditor.java} (77%)

[myfaces-tobago] 02/03: feat: progress on date input

Posted by lo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 1891cac3b66a0f16237d5317e9bad787d18a1989
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Thu Apr 29 19:15:38 2021 +0200

    feat: progress on date input
    
    better type support
    demo
    remove picker icon, because it comes sometimes from the browser
    
    issue: TOBAGO-2071
---
 .../tobago/renderkit/html/HtmlInputTypesEditor.java   | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlInputTypesEditor.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlInputTypesEditor.java
index e23eaad..63fdcdc 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlInputTypesEditor.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlInputTypesEditor.java
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.myfaces.tobago.renderkit.html;
 
 import org.apache.myfaces.tobago.apt.annotation.Preliminary;

[myfaces-tobago] 01/03: feat: progress on date input

Posted by lo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 45b6f807e465678fbc1be0ffb51c4e77762b9020
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Thu Apr 29 19:15:38 2021 +0200

    feat: progress on date input
    
    better type support
    demo
    remove picker icon, because it comes sometimes from the browser
    
    issue: TOBAGO-2071
---
 .../tobago/internal/component/AbstractUIDate.java  |  13 +--
 .../internal/renderkit/renderer/DateRenderer.java  | 116 +++++++++++----------
 .../taglib/component/DateTagDeclaration.java       |  20 ++++
 .../tobago/renderkit/css/CustomClassEditor.java    |   5 -
 .../renderkit/html/HtmlInputTypesEditor.java       |  22 ++++
 .../src/test/resources/renderer/date/dateAuto.html |   1 -
 .../src/test/resources/renderer/date/dateBoth.html |   2 -
 .../src/test/resources/renderer/date/dateDate.html |   1 -
 .../src/test/resources/renderer/date/dateTime.html |   1 -
 .../resources/renderer/date/localDateAuto.html     |   1 -
 .../resources/renderer/date/localDateTimeAuto.html |   2 -
 .../resources/renderer/date/localTimeAuto.html     |   1 -
 .../src/test/resources/renderer/date/minMax.html   |   1 -
 .../test/resources/renderer/date/testLabel.html    |   1 -
 .../resources/renderer/date/testTodayButton.html   |   1 -
 .../src/test/resources/renderer/date/text.html     |   2 -
 .../resources/renderer/date/zonedDateTimeAuto.html |   2 -
 .../tobago/example/demo/DateController.java        |  94 +++++++++++++++++
 .../20-component/010-input/40-date/Date.test.js    |  42 +++-----
 .../20-component/010-input/40-date/Date.xhtml      |  60 +++++++++--
 .../org/apache/myfaces/tobago/apt/component.stg    |   4 +
 21 files changed, 270 insertions(+), 122 deletions(-)

diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java
index f3c6db7..470d96e 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIDate.java
@@ -26,17 +26,8 @@ import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
  */
 public abstract class AbstractUIDate extends AbstractUIInput {
 
-  private transient HtmlInputTypes type;
   private transient String pattern;
 
-  public HtmlInputTypes getType() {
-    return type;
-  }
-
-  public void setType(HtmlInputTypes type) {
-    this.type = type;
-  }
-
   public String getPattern() {
     return pattern;
   }
@@ -47,6 +38,10 @@ public abstract class AbstractUIDate extends AbstractUIInput {
 
   public abstract boolean isTodayButton();
 
+  public abstract HtmlInputTypes getType();
+
+  public abstract void setType(HtmlInputTypes type);
+
   public abstract Object getMin();
 
   public abstract Object getMax();
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 41f2011..362b756 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
@@ -101,7 +101,7 @@ public class DateRenderer<T extends AbstractUIDate> extends MessageLayoutRendere
 //    writer.writeAttribute(HtmlAttributes.PATTERN,
 //    new DateFormatUtils.DateTimeJavaScriptPattern(input.getPattern()).getDatePattern(), true);
     final HtmlInputTypes type = date.getType();
-    if (date.getType() == HtmlInputTypes.TEXT) {
+    if (type == HtmlInputTypes.TEXT) {
       // todo
       final DateFormatUtils.DateTimeJavaScriptPattern patterns
           = new DateFormatUtils.DateTimeJavaScriptPattern(date.getPattern());
@@ -170,12 +170,12 @@ public class DateRenderer<T extends AbstractUIDate> extends MessageLayoutRendere
 
     encodeBehavior(writer, facesContext, component);
 
-    if (type.supportsDate()) {
-      encodeButton(facesContext, component, FaIcons.CALENDAR);
-    }
-    if (type.supportsTime()) {
-      encodeButton(facesContext, component, FaIcons.CLOCK_O);
-    }
+//    if (type.supportsDate()) {
+//      encodeButton(facesContext, component, FaIcons.CALENDAR);
+//    }
+//    if (type.supportsTime()) {
+//      encodeButton(facesContext, component, FaIcons.CLOCK_O);
+//    }
   }
 
   private String convertToString(Object value) {
@@ -261,6 +261,9 @@ public class DateRenderer<T extends AbstractUIDate> extends MessageLayoutRendere
         } else if (estimatedType.isAssignableFrom(ZonedDateTime.class)) {
           dateTimeConverter.setType("zonedDateTime");
           dateTimeConverter.setPattern(PATTERN_DATETIME);
+        } else if (estimatedType.isAssignableFrom(Long.class)) {
+          dateTimeConverter.setType("date");
+          dateTimeConverter.setPattern(PATTERN_DATE);
         } else if (estimatedType.isAssignableFrom(Date.class)) {
           dateTimeConverter.setType("date");
           dateTimeConverter.setPattern(PATTERN_DATE);
@@ -320,72 +323,77 @@ public class DateRenderer<T extends AbstractUIDate> extends MessageLayoutRendere
   private void prepare(final FacesContext facesContext, final T component) {
     HtmlInputTypes type = component.getType();
     String pattern = component.getPattern();
+
+    DateTimeConverter converter = null;
     if (type == null || pattern == null) {
-      Converter converter = getConverter(facesContext, component, component.getSubmittedValue()); // XXX submitted?
-      if (converter instanceof DateTimeConverter) {
-        DateTimeConverter dtConverter = (DateTimeConverter) converter;
-        String t = dtConverter.getType();
-        if (TYPE_DATE.equals(t)) {
+      Converter someConverter = getConverter(facesContext, component, component.getSubmittedValue()); // XXX submitted?
+      if (someConverter instanceof DateTimeConverter) {
+        converter = (DateTimeConverter) someConverter;
+      }
+    }
+
+    if (type == null) {
+      if (converter != null) {
+        final String typeFromConverter = converter.getType();
+        if (TYPE_DATE.equals(typeFromConverter)) {
           type = HtmlInputTypes.DATE;
-        } else if (TYPE_BOTH.equals(t)) {
+        } else if (TYPE_BOTH.equals(typeFromConverter)) {
           type = HtmlInputTypes.DATETIME_LOCAL;
-        } else if (TYPE_TIME.equals(t)) {
+        } else if (TYPE_TIME.equals(typeFromConverter)) {
           type = HtmlInputTypes.TIME;
-        } else if (TYPE_LOCAL_DATE.equals(t)) {
+        } else if (TYPE_LOCAL_DATE.equals(typeFromConverter)) {
           type = HtmlInputTypes.DATE;
-        } else if (TYPE_LOCAL_DATE_TIME.equals(t)) {
+        } else if (TYPE_LOCAL_DATE_TIME.equals(typeFromConverter)) {
           type = HtmlInputTypes.DATETIME_LOCAL;
-        } else if (TYPE_LOCAL_TIME.equals(t)) {
+        } else if (TYPE_LOCAL_TIME.equals(typeFromConverter)) {
           type = HtmlInputTypes.TIME;
-        } else if (TYPE_ZONED_DATE_TIME.equals(t)) {
+        } else if (TYPE_ZONED_DATE_TIME.equals(typeFromConverter)) {
           type = HtmlInputTypes.DATETIME_LOCAL;
-        } else if (TYPE_OFFSET_DATE_TIME.equals(t)) {
+        } else if (TYPE_OFFSET_DATE_TIME.equals(typeFromConverter)) {
           type = HtmlInputTypes.DATETIME_LOCAL;
-        } else if (TYPE_OFFSET_TIME.equals(t)) {
+        } else if (TYPE_OFFSET_TIME.equals(typeFromConverter)) {
           type = HtmlInputTypes.TIME;
-        } else if (TYPE_MONTH.equals(t)) {
+        } else if (TYPE_MONTH.equals(typeFromConverter)) {
           type = HtmlInputTypes.MONTH;
-        } else if (TYPE_WEEK.equals(t)) {
+        } else if (TYPE_WEEK.equals(typeFromConverter)) {
           type = HtmlInputTypes.WEEK;
-        } else {
+        } else { // unknown type
           type = HtmlInputTypes.TEXT;
         }
-        pattern = dtConverter.getPattern();
-        if (pattern == null) {
-          if (TYPE_DATE.equals(t)) {
-            pattern = PATTERN_DATE;
-          } else if (TYPE_BOTH.equals(t)) {
-            pattern = PATTERN_DATETIME;
-          } else if (TYPE_TIME.equals(t)) {
-            pattern = PATTERN_TIME;
-          } else if (TYPE_LOCAL_DATE.equals(t)) {
-            pattern = PATTERN_DATE;
-          } else if (TYPE_LOCAL_DATE_TIME.equals(t)) {
-            pattern = PATTERN_DATETIME;
-          } else if (TYPE_LOCAL_TIME.equals(t)) {
-            pattern = PATTERN_TIME;
-          } else if (TYPE_ZONED_DATE_TIME.equals(t)) {
-            pattern = PATTERN_DATETIME;
-          } else if (TYPE_OFFSET_DATE_TIME.equals(t)) {
-            pattern = PATTERN_DATETIME;
-          } else if (TYPE_OFFSET_TIME.equals(t)) {
-            pattern = PATTERN_TIME;
-          } else if (TYPE_MONTH.equals(t)) {
-            pattern = PATTERN_MONTH;
-          } else if (TYPE_WEEK.equals(t)) {
-            pattern = PATTERN_WEEK;
-          } else {
-            pattern = DateFormatUtils.findPattern(dtConverter);
-          }
-        } else {
-          pattern = PATTERN_DATETIME;
-        }
       } else {
         type = HtmlInputTypes.TEXT;
       }
     }
+
+    if (pattern == null && converter != null) {
+      pattern = converter.getPattern();
+    }
+
+    if (pattern == null) {
+      switch (type) {
+        case DATE:
+          pattern = PATTERN_DATE;
+          break;
+        case TIME:
+          pattern = PATTERN_TIME;
+          break;
+        case DATETIME_LOCAL:
+        case DATETIME:
+          pattern = PATTERN_DATETIME;
+          break;
+        case MONTH:
+          pattern = PATTERN_MONTH;
+          break;
+        case WEEK:
+          pattern = PATTERN_WEEK;
+          break;
+        case TEXT:
+        default:
+          pattern = PATTERN_DATETIME;
+      }
+    }
+
     component.setPattern(pattern);
     component.setType(type);
   }
-
 }
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/DateTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/DateTagDeclaration.java
index a4c6255..2c3f3b1 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/DateTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/DateTagDeclaration.java
@@ -20,6 +20,7 @@
 package org.apache.myfaces.tobago.internal.taglib.component;
 
 import org.apache.myfaces.tobago.apt.annotation.Behavior;
+import org.apache.myfaces.tobago.apt.annotation.Preliminary;
 import org.apache.myfaces.tobago.apt.annotation.Tag;
 import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
 import org.apache.myfaces.tobago.apt.annotation.UIComponentTag;
@@ -47,6 +48,7 @@ import org.apache.myfaces.tobago.internal.taglib.declaration.IsFocus;
 import org.apache.myfaces.tobago.internal.taglib.declaration.IsReadonly;
 import org.apache.myfaces.tobago.internal.taglib.declaration.IsRequired;
 import org.apache.myfaces.tobago.internal.taglib.declaration.IsVisual;
+import org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes;
 
 import javax.faces.component.UIInput;
 
@@ -104,4 +106,22 @@ public interface DateTagDeclaration
   @TagAttribute
   @UIComponentTagAttribute(type = {"java.time.LocalDate", "java.util.Date"})
   void setMax(String max);
+
+  /**
+   * XXX Preliminary: check if this is the right way
+   *
+   * Type of the date/time input.
+   */
+  @Preliminary
+  @TagAttribute
+  @UIComponentTagAttribute(
+      type = "org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes",
+      allowedValues = {
+          HtmlInputTypes.STRING_DATE,
+          HtmlInputTypes.STRING_TIME,
+          HtmlInputTypes.STRING_DATETIME_LOCAL,
+          HtmlInputTypes.STRING_MONTH,
+          HtmlInputTypes.STRING_WEEK
+      })
+  void setType(String type);
 }
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClassEditor.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClassEditor.java
index a1ca57c..9c1996f 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClassEditor.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/css/CustomClassEditor.java
@@ -19,18 +19,13 @@
 
 package org.apache.myfaces.tobago.renderkit.css;
 
-import org.apache.myfaces.tobago.apt.annotation.Preliminary;
-
 import java.beans.PropertyEditorSupport;
 
 /**
  * Converter for {@link org.apache.myfaces.tobago.renderkit.css.CustomClass}
  *
- * XXX preliminary
- *
  * @since 3.0.0
  */
-@Preliminary
 public class CustomClassEditor extends PropertyEditorSupport {
 
   @Override
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlInputTypesEditor.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlInputTypesEditor.java
new file mode 100644
index 0000000..e23eaad
--- /dev/null
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/renderkit/html/HtmlInputTypesEditor.java
@@ -0,0 +1,22 @@
+package org.apache.myfaces.tobago.renderkit.html;
+
+import org.apache.myfaces.tobago.apt.annotation.Preliminary;
+
+import java.beans.PropertyEditorSupport;
+
+/**
+ * XXX Preliminary: check if this is the right way
+ *
+ * Converter for {@link org.apache.myfaces.tobago.renderkit.html.HtmlInputTypes}
+ *
+ * @since 5.0.0
+ */
+@Preliminary
+public class HtmlInputTypesEditor extends PropertyEditorSupport {
+
+  @Override
+  public void setAsText(final String text) throws IllegalArgumentException {
+    setValue(HtmlInputTypes.valueOf(text));
+  }
+
+}
diff --git a/tobago-core/src/test/resources/renderer/date/dateAuto.html b/tobago-core/src/test/resources/renderer/date/dateAuto.html
index 42e10ab..5eef08f 100644
--- a/tobago-core/src/test/resources/renderer/date/dateAuto.html
+++ b/tobago-core/src/test/resources/renderer/date/dateAuto.html
@@ -19,7 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='date' name='id' id='id::field' value='1957-10-04' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/dateBoth.html b/tobago-core/src/test/resources/renderer/date/dateBoth.html
index d03ddcc..b588f1f 100644
--- a/tobago-core/src/test/resources/renderer/date/dateBoth.html
+++ b/tobago-core/src/test/resources/renderer/date/dateBoth.html
@@ -19,8 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='datetime-local' name='id' id='id::field' value='1957-10-04T19:28:34' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-clock-o'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/dateDate.html b/tobago-core/src/test/resources/renderer/date/dateDate.html
index 42e10ab..5eef08f 100644
--- a/tobago-core/src/test/resources/renderer/date/dateDate.html
+++ b/tobago-core/src/test/resources/renderer/date/dateDate.html
@@ -19,7 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='date' name='id' id='id::field' value='1957-10-04' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/dateTime.html b/tobago-core/src/test/resources/renderer/date/dateTime.html
index b78b348..9b0cc0a 100644
--- a/tobago-core/src/test/resources/renderer/date/dateTime.html
+++ b/tobago-core/src/test/resources/renderer/date/dateTime.html
@@ -19,7 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='time' name='id' id='id::field' value='19:28:34' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-clock-o'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/localDateAuto.html b/tobago-core/src/test/resources/renderer/date/localDateAuto.html
index 03f7296..118a46f 100644
--- a/tobago-core/src/test/resources/renderer/date/localDateAuto.html
+++ b/tobago-core/src/test/resources/renderer/date/localDateAuto.html
@@ -19,7 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='date' name='id' id='id::field' value='1957-10-05' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/localDateTimeAuto.html b/tobago-core/src/test/resources/renderer/date/localDateTimeAuto.html
index 1aa041b..6e0f137 100644
--- a/tobago-core/src/test/resources/renderer/date/localDateTimeAuto.html
+++ b/tobago-core/src/test/resources/renderer/date/localDateTimeAuto.html
@@ -19,8 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='datetime-local' name='id' id='id::field' value='1957-10-05T00:28:34.123' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-clock-o'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/localTimeAuto.html b/tobago-core/src/test/resources/renderer/date/localTimeAuto.html
index fca219c..cbc64cb 100644
--- a/tobago-core/src/test/resources/renderer/date/localTimeAuto.html
+++ b/tobago-core/src/test/resources/renderer/date/localTimeAuto.html
@@ -19,7 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='time' name='id' id='id::field' value='00:28:34.123' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-clock-o'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/minMax.html b/tobago-core/src/test/resources/renderer/date/minMax.html
index 569606a..a69abbc 100644
--- a/tobago-core/src/test/resources/renderer/date/minMax.html
+++ b/tobago-core/src/test/resources/renderer/date/minMax.html
@@ -19,7 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='date' name='id' id='id::field' value='1957-10-05' min='1957-09-05' max='1957-11-04' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/testLabel.html b/tobago-core/src/test/resources/renderer/date/testLabel.html
index 78d7767..6770b4d 100644
--- a/tobago-core/src/test/resources/renderer/date/testLabel.html
+++ b/tobago-core/src/test/resources/renderer/date/testLabel.html
@@ -20,7 +20,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='date' name='id' id='id::field' value='1957-10-05' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/testTodayButton.html b/tobago-core/src/test/resources/renderer/date/testTodayButton.html
index 508299c..278cbb6 100644
--- a/tobago-core/src/test/resources/renderer/date/testTodayButton.html
+++ b/tobago-core/src/test/resources/renderer/date/testTodayButton.html
@@ -20,7 +20,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='date' name='id' id='id::field' value='1957-10-05' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/text.html b/tobago-core/src/test/resources/renderer/date/text.html
index 4a57a46..4895e54 100644
--- a/tobago-core/src/test/resources/renderer/date/text.html
+++ b/tobago-core/src/test/resources/renderer/date/text.html
@@ -19,8 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='text' name='id' id='id::field' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-clock-o'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-core/src/test/resources/renderer/date/zonedDateTimeAuto.html b/tobago-core/src/test/resources/renderer/date/zonedDateTimeAuto.html
index 1aa041b..6e0f137 100644
--- a/tobago-core/src/test/resources/renderer/date/zonedDateTimeAuto.html
+++ b/tobago-core/src/test/resources/renderer/date/zonedDateTimeAuto.html
@@ -19,8 +19,6 @@
   <div class='tobago-input-group-outer'>
     <div class='input-group'>
       <input type='datetime-local' name='id' id='id::field' value='1957-10-05T00:28:34.123' class='form-control'>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-calendar'></i></button>
-      <button class='btn btn-secondary tobago-date-picker' type='button' title='Date Picker'><i class='fa fa-clock-o'></i></button>
     </div>
   </div>
 </tobago-date>
\ No newline at end of file
diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateController.java
index 8662fbc..1fc5364 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateController.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateController.java
@@ -23,13 +23,21 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.enterprise.context.RequestScoped;
+import javax.faces.application.FacesMessage;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.event.ActionEvent;
+import javax.faces.validator.ValidatorException;
 import javax.inject.Named;
 import java.io.Serializable;
 import java.lang.invoke.MethodHandles;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
+import java.time.Instant;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.time.ZoneId;
 import java.util.Date;
 
 @RequestScoped
@@ -56,6 +64,15 @@ public class DateController implements Serializable {
   private final LocalDate partyMin = today.plusDays(3);
   private final LocalDate partyMax = today.plusDays(10);
 
+  private String timezoneString = "Europe/London";
+
+  private LocalDate typeLocalDate = SPUTNIK_LOCAL_DATE_TIME.toLocalDate();
+  private LocalDateTime typeLocalDateTime = SPUTNIK_LOCAL_DATE_TIME;
+  private LocalTime typeLocalTime = SPUTNIK_LOCAL_DATE_TIME.toLocalTime().withSecond(0).withNano(0);
+  private Date typeDate;
+  private Long typeLong;
+  private String typeString;
+
   public DateController() {
     once = new Date();
     final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
@@ -64,6 +81,27 @@ public class DateController implements Serializable {
     } catch (final ParseException e) {
       LOG.error("Unexpected parse exception", e);
     }
+    timeZoneChanged();
+  }
+
+  private void timeZoneChanged() {  // XXX buggy
+    final Instant instant = SPUTNIK_LOCAL_DATE_TIME.atZone(ZoneId.of(timezoneString)).toInstant();
+    typeDate = Date.from(instant);
+    typeLong = typeDate.getTime();
+    typeString = typeDate.toString();
+  }
+
+  public void timeZoneValidator(
+      final FacesContext facesContext, final UIComponent uiComponent, final Object string) throws ValidatorException {
+    try {
+      ZoneId.of((String)string);
+    } catch (Exception e) {
+      throw new ValidatorException(new FacesMessage("Invalid Time Zone Identifier!"), e);
+    }
+  }
+
+  public void timeZoneChanged(ActionEvent event) {
+    timeZoneChanged();
   }
 
   public Date getOnce() {
@@ -129,4 +167,60 @@ public class DateController implements Serializable {
   public LocalDate getPartyMax() {
     return partyMax;
   }
+
+  public String getTimezoneString() {
+    return timezoneString;
+  }
+
+  public void setTimezoneString(String timezoneString) {
+    this.timezoneString = timezoneString;
+  }
+
+  public LocalDate getTypeLocalDate() {
+    return typeLocalDate;
+  }
+
+  public void setTypeLocalDate(LocalDate typeLocalDate) {
+    this.typeLocalDate = typeLocalDate;
+  }
+
+  public LocalDateTime getTypeLocalDateTime() {
+    return typeLocalDateTime;
+  }
+
+  public void setTypeLocalDateTime(LocalDateTime typeLocalDateTime) {
+    this.typeLocalDateTime = typeLocalDateTime;
+  }
+
+  public LocalTime getTypeLocalTime() {
+    return typeLocalTime;
+  }
+
+  public void setTypeLocalTime(LocalTime typeLocalTime) {
+    this.typeLocalTime = typeLocalTime;
+  }
+
+  public Date getTypeDate() {
+    return typeDate;
+  }
+
+  public void setTypeDate(Date typeDate) {
+    this.typeDate = typeDate;
+  }
+
+  public Long getTypeLong() {
+    return typeLong;
+  }
+
+  public void setTypeLong(Long typeLong) {
+    this.typeLong = typeLong;
+  }
+
+  public String getTypeString() {
+    return typeString;
+  }
+
+  public void setTypeString(String typeString) {
+    this.typeString = typeString;
+  }
 }
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/40-date/Date.test.js b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/40-date/Date.test.js
index 4af9737..7a1fa0b 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/40-date/Date.test.js
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/40-date/Date.test.js
@@ -15,13 +15,9 @@
  * limitations under the License.
  */
 
+import {querySelectorFn} from "/script/tobago-test.js";
 import {JasmineTestTool} from "/tobago/test/tobago-test-tool.js";
 
-it("not implemented yet", function (done) {
-  let test = new JasmineTestTool(done);
-  test.do(() => fail("not implemented yet"));
-  test.start();
-});
 /*
 
 function getToday(dateFieldFn) {
@@ -29,32 +25,24 @@ function getToday(dateFieldFn) {
   let todayArray = tobagoToday.split("-");
   return todayArray[2] + "." + todayArray[1] + "." + todayArray[0];
 }
-
-QUnit.test("date with label", function (assert) {
-  assert.expect(5);
+*/
+it("inputfield with label", function (done) {
 
   let labelFn = querySelectorFn("#page\\:mainForm\\:dNormal > label");
   let dateFieldFn = querySelectorFn("#page\\:mainForm\\:dNormal\\:\\:field");
-  let dateButtonFn = querySelectorFn("#page\\:mainForm\\:dNormal button");
-  let dayTodayFn = querySelectorFn(".day.today");
-  let today = getToday(dateFieldFn);
-
-  assert.equal(labelFn().textContent, "Date");
-  assert.equal(dateFieldFn().value, today);
-
-  dateFieldFn().value = "32.05.2016";
-  dateButtonFn().dispatchEvent(new Event("click", {bubbles: true}));
-
-  assert.equal(dateFieldFn().value, today);
-  assert.notOk(dayTodayFn().classList.contains("past"));
-  if (dayTodayFn().previousElementSibling !== null) {
-    assert.ok(dayTodayFn().previousElementSibling.classList.contains("past"));
-  } else {
-    assert.notOk(dayTodayFn().nextElementSibling.classList.contains("past"));
-  }
-
-  dateButtonFn().dispatchEvent(new Event("click", {bubbles: true})); // IE11: close datetimepicker for next test
+  // let dateButtonFn = querySelectorFn("#page\\:mainForm\\:dNormal button");
+  // let dayTodayFn = querySelectorFn(".day.today");
+  let sputnik = "1969-07-20";
+  let other = "1999-12-31";
+
+  const test = new JasmineTestTool(done);
+  test.do(() => expect(labelFn().textContent).toBe("Date"));
+  test.do(() => expect(dateFieldFn().value).toBe(sputnik));
+  test.do(() => dateFieldFn().value = other);
+  test.do(() => expect(dateFieldFn().value).toBe(other));
+  test.start();
 });
+/*
 
 QUnit.test("date+time pattern", function (assert) {
   let dateButtonFn = querySelectorFn("#page\\:mainForm\\:dateTimePattern .datepickerbutton");
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/40-date/Date.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/40-date/Date.xhtml
index 2b04906..e834a81 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/40-date/Date.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/20-component/010-input/40-date/Date.xhtml
@@ -34,14 +34,8 @@
   </p>
 
   <tc:section label="Basics">
-    <p>In general, a date should always have a label. To get a label use the <code>label</code> attribute.</p>
-    <p>It is recommended to use a pattern. For that, use <code>&lt;f:convertDateTime&gt;</code>.</p>
-    <p>The <code>value</code> must be a
-      <tc:link label="Date" link="https://docs.oracle.com/javase/8/docs/api/java/util/Date.html"/>
-      or a string with a matching pattern.</p>
-        <demo-highlight language="markup">&lt;tc:date label="Date" value="\#{dateController.now}"&gt;
-  &lt;f:convertDateTime pattern="dd.MM.yyyy"/&gt;
-&lt;/tc:date&gt;</demo-highlight>
+    <p>In general, a date had a label. To get a label use the <code>label</code> attribute, <code>&lt;tc:in&gt;</code>.</p>
+        <demo-highlight language="markup">&lt;tc:date label="Date" value="\#{dateController.sputnikLd}"/&gt;</demo-highlight>
     <tc:date id="dNormal" label="Date" value="#{dateController.sputnikLd}"/>
     <tc:date id="dReadonly" label="Read Only" readonly="true" value="#{dateController.now}"/>
     <tc:date id="d3" label="Disabled" disabled="true" value="#{dateController.now}"/>
@@ -51,12 +45,56 @@
   <tc:section label="Focus">
     <p>The following date should be selected after reloading the page. This can be done with the attribute
       <code>focus</code>.</p>
-        <demo-highlight language="markup">&lt;tc:date label="Date (focus)" focus="true"&gt;
-  &lt;f:convertDateTime pattern="dd.MM.yyyy"/&gt;
-&lt;/tc:date&gt;</demo-highlight>
+        <demo-highlight language="markup">&lt;tc:date label="Date (focus)" focus="true"/&gt;&gt;</demo-highlight>
     <tc:date id="d5" label="Date (focus)" focus="true"/>
   </tc:section>
 
+  <tc:section label="Types">
+    <p><tc:badge value="New!" markup="info"/>
+      It is NOT recommended to use <code>&lt;f:convertDateTime&gt;</code>,
+      in most cases the converter will be configured automatically.</p>
+    <p>The <code>value</code> must be one of a set of several types.
+      There are some new classes
+      from <tc:link label="JEP 150" link="http://openjdk.java.net/jeps/150"/>
+      since Java 8, which are generally preferred to use
+      (there are several discussions in the net).
+    </p>
+    <ul>
+      <li><tc:link label="java.time.LocalDate" link="https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html"/></li>
+      <li><tc:link label="java.time.LocalDateTime" link="https://docs.oracle.com/javase/8/docs/api/java/time/LocalDateTime.html"/></li>
+      <li><tc:link label="java.time.LocalTime" link="https://docs.oracle.com/javase/8/docs/api/java/time/LocalTime.html"/></li>
+      <li><tc:link label="java.util.Date" link="https://docs.oracle.com/javase/8/docs/api/java/util/Date.html"/> (not recommended)</li>
+      <li><tc:link label="java.lang.Long" link="https://docs.oracle.com/javase/8/docs/api/java/lang/Long.html"/> (not recommended)</li>
+      <li><tc:link label="java.lang.String" link="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html"/> for plain text (TBD)</li>
+    </ul>
+    <p>
+      Technical hint: Until Tobago 4 the user readable localized formatted String (e. g. 12/31/2050) was rendered into the HTML file and
+      was post back to the server.
+      <tc:badge value="New!" markup="info"/>
+      Since Tobago 5 the string will be tranfered as ISO 8601 (e. g. 2050-12-31) to satisfy the HTML5 specification for
+      input type="date", type="time" and type="datetimelocal".
+    </p>
+    <tc:date id="typeLocalDate" label="LocalDate" value="#{dateController.typeLocalDate}"/>
+    <tc:date id="typeLocalDateTime" label="LocalDateTime" value="#{dateController.typeLocalDateTime}"/>
+    <tc:date id="typeLocalTime" label="LocalTime" value="#{dateController.typeLocalTime}"/>
+
+    <tc:in id="zone" label="Time Zone" value="#{dateController.timezoneString}"
+           validator="#{dateController.timeZoneValidator}">
+      <f:facet name="after">
+        <tc:button image="fa-refresh" tip="Update" actionListener="#{dateController.timeZoneChanged}">
+          <f:ajax render="mainForm" execute="zone"/>
+        </tc:button>
+      </f:facet>
+    </tc:in>
+    <tc:date id="typeDate" label="Date (as date)" value="#{dateController.typeDate}"/>
+    <tc:date id="typeDateAsTimeC" label="Date (as time)" value="#{dateController.typeDate}">
+      <f:convertDateTime type="time"/>
+    </tc:date>
+    <tc:date id="typeLong" label="Long" value="#{dateController.typeLong}"/>
+<!--    <tc:date id="typeCalendar" label="Calendar" value="#{dateController.typeCalendar}"/>-->
+    <tc:date id="typeString" label="String" value="#{dateController.typeString}"/>
+  </tc:section>
+
   <tc:section label="Required">
     <p>A date can be set as required with the <code>required</code> attribute.
       Such a date must contain a value, otherwise a submit is not possible.
diff --git a/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg b/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg
index 45c59c4..d546745 100644
--- a/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg
+++ b/tobago-tool/tobago-tool-apt/src/main/resources/org/apache/myfaces/tobago/apt/component.stg
@@ -403,6 +403,10 @@ JustifyContentProperty(property) ::= <<
 <NormalProperty(property)>
 >>
 
+HtmlInputTypesProperty(property) ::= <<
+<NormalProperty(property)>
+>>
+
 SwitchTypeProperty(property) ::= <<
 <NormalProperty(property)>
 >>

[myfaces-tobago] 03/03: feat: progress on date input

Posted by lo...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lofwyr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit fa1ecb73476baca147f8c9ad1193d55b8242af80
Author: Udo Schnurpfeil <ud...@irian.eu>
AuthorDate: Fri Apr 30 10:18:15 2021 +0200

    feat: progress on date input
    
    better type support
    demo
    remove picker icon, because it comes sometimes from the browser
    
    issue: TOBAGO-2071
---
 .../java/org/apache/myfaces/tobago/example/demo/DateController.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateController.java b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateController.java
index 1fc5364..27ce57c 100644
--- a/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateController.java
+++ b/tobago-example/tobago-example-demo/src/main/java/org/apache/myfaces/tobago/example/demo/DateController.java
@@ -94,7 +94,7 @@ public class DateController implements Serializable {
   public void timeZoneValidator(
       final FacesContext facesContext, final UIComponent uiComponent, final Object string) throws ValidatorException {
     try {
-      ZoneId.of((String)string);
+      ZoneId.of((String) string);
     } catch (Exception e) {
       throw new ValidatorException(new FacesMessage("Invalid Time Zone Identifier!"), e);
     }