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 2022/11/30 14:58:45 UTC
[myfaces-tobago] branch tobago-5.x updated: T5 autocomplete (#3473)
This is an automated email from the ASF dual-hosted git repository.
lofwyr pushed a commit to branch tobago-5.x
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git
The following commit(s) were added to refs/heads/tobago-5.x by this push:
new 45c63b522c T5 autocomplete (#3473)
45c63b522c is described below
commit 45c63b522cc35d6ce0c5a1c45dc91cd237a621ba
Author: Udo Schnurpfeil <lo...@apache.org>
AuthorDate: Wed Nov 30 15:58:39 2022 +0100
T5 autocomplete (#3473)
* feat: autocomplete
issue: TOBAGO-2175
issue: TOBAGO-2176
---
.../SupportsAutocomplete.java} | 33 +++++++++++++++-------
.../tobago/internal/component/AbstractUIIn.java | 4 ++-
.../internal/component/AbstractUITextarea.java | 3 +-
.../internal/renderkit/renderer/InRenderer.java | 1 +
.../renderkit/renderer/TextareaRenderer.java | 1 +
.../taglib/component/TextareaTagDeclaration.java | 4 ++-
.../taglib/declaration/HasAutocomplete.java | 2 +-
.../renderkit/renderer/InRendererUnitTest.java | 11 ++++++++
.../renderer/TextareaRendererUnitTest.java | 10 +++++++
.../resources/renderer/in/autocomplete-on.html | 20 +++++++++++++
.../renderer/textarea/autocomplete-impp.html | 20 +++++++++++++
.../main/webapp/content/010-input/10-in/In.xhtml | 12 ++++++++
.../content/010-input/30-textarea/Textarea.xhtml | 12 ++++++++
13 files changed, 119 insertions(+), 14 deletions(-)
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITextarea.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/SupportsAutocomplete.java
similarity index 54%
copy from tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITextarea.java
copy to tobago-core/src/main/java/org/apache/myfaces/tobago/component/SupportsAutocomplete.java
index 47298d39e4..bbfce0b73e 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITextarea.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/component/SupportsAutocomplete.java
@@ -17,18 +17,31 @@
* under the License.
*/
-package org.apache.myfaces.tobago.internal.component;
+package org.apache.myfaces.tobago.component;
-import org.apache.myfaces.tobago.sanitizer.SanitizeMode;
+import java.util.Objects;
-/**
- * {@link org.apache.myfaces.tobago.internal.taglib.component.TextareaTagDeclaration}
- */
-public abstract class AbstractUITextarea extends AbstractUIInput {
-
- public abstract String getPlaceholder();
+public interface SupportsAutocomplete {
- public abstract SanitizeMode getSanitize();
+ default String getAutocompleteString() {
+ final Object object = getAutocomplete();
+ if (object == null) {
+ return null;
+ } else if (object instanceof Boolean) {
+ return ((Boolean) object) ? "on" : "off";
+ } else if (object instanceof String) {
+ final String string = (String) object;
+ if (string.equals("true")) {
+ return "on";
+ } else if (string.equals("false")) {
+ return "off";
+ } else {
+ return string;
+ }
+ } else {
+ return Objects.toString(object);
+ }
+ }
- public abstract Integer getRows();
+ Object getAutocomplete();
}
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIIn.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIIn.java
index 00bb977792..9298fdada4 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIIn.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUIIn.java
@@ -19,10 +19,12 @@
package org.apache.myfaces.tobago.internal.component;
+import org.apache.myfaces.tobago.component.SupportsAutocomplete;
+
/**
* {@link org.apache.myfaces.tobago.internal.taglib.component.InTagDeclaration}
*/
-public abstract class AbstractUIIn extends AbstractUIInput {
+public abstract class AbstractUIIn extends AbstractUIInput implements SupportsAutocomplete {
public abstract String getPlaceholder();
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITextarea.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITextarea.java
index 47298d39e4..93061a9804 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITextarea.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/component/AbstractUITextarea.java
@@ -19,12 +19,13 @@
package org.apache.myfaces.tobago.internal.component;
+import org.apache.myfaces.tobago.component.SupportsAutocomplete;
import org.apache.myfaces.tobago.sanitizer.SanitizeMode;
/**
* {@link org.apache.myfaces.tobago.internal.taglib.component.TextareaTagDeclaration}
*/
-public abstract class AbstractUITextarea extends AbstractUIInput {
+public abstract class AbstractUITextarea extends AbstractUIInput implements SupportsAutocomplete {
public abstract String getPlaceholder();
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRenderer.java
index 9038830730..abbf2cc12e 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRenderer.java
@@ -141,6 +141,7 @@ public class InRenderer<T extends AbstractUIIn> extends MessageLayoutRendererBas
if (!disabled && !readonly) {
writer.writeAttribute(HtmlAttributes.PLACEHOLDER, component.getPlaceholder(), true);
}
+ writer.writeAttribute(HtmlAttributes.AUTOCOMPLETE, component.getAutocompleteString(), true);
writer.writeClassAttribute(
markup != null && markup.contains(Markup.NUMBER) ? TobagoClass.NUMBER : null,
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TextareaRenderer.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TextareaRenderer.java
index 5bc458ea6e..4494e8aa3f 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TextareaRenderer.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TextareaRenderer.java
@@ -95,6 +95,7 @@ public class TextareaRenderer<T extends AbstractUITextarea> extends MessageLayou
writer.writeAttribute(HtmlAttributes.DISABLED, disabled);
writer.writeAttribute(HtmlAttributes.REQUIRED, component.isRequired());
writer.writeAttribute(HtmlAttributes.TABINDEX, component.getTabIndex());
+ writer.writeAttribute(HtmlAttributes.AUTOCOMPLETE, component.getAutocompleteString(), true);
if (component.getAccessKey() != null) {
writer.writeAttribute(HtmlAttributes.ACCESSKEY, Character.toString(component.getAccessKey()), false);
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TextareaTagDeclaration.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TextareaTagDeclaration.java
index 967818847f..39f69bdf08 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TextareaTagDeclaration.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/component/TextareaTagDeclaration.java
@@ -28,6 +28,7 @@ import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
import org.apache.myfaces.tobago.component.ClientBehaviors;
import org.apache.myfaces.tobago.component.RendererTypes;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasAccessKey;
+import org.apache.myfaces.tobago.internal.taglib.declaration.HasAutocomplete;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasConverter;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasConverterMessage;
import org.apache.myfaces.tobago.internal.taglib.declaration.HasHelp;
@@ -92,7 +93,8 @@ import javax.faces.component.UIInput;
public interface TextareaTagDeclaration
extends HasIdBindingAndRendered, HasConverter, IsReadonly, IsDisabled, IsRequired, HasLabel, HasLabelLayout, HasTip,
HasHelp, HasAccessKey, HasValidator, HasValue, HasValueChangeListener, HasTabIndex, IsFocus, IsVisual,
- HasValidatorMessage, HasConverterMessage, HasRequiredMessage, HasSanitize, HasPlaceholder, HasAutoSpacing {
+ HasValidatorMessage, HasConverterMessage, HasRequiredMessage, HasSanitize, HasPlaceholder, HasAutoSpacing,
+ HasAutocomplete {
/**
* The row count for this component.
diff --git a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasAutocomplete.java b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasAutocomplete.java
index 5dfb561053..30c0be3241 100644
--- a/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasAutocomplete.java
+++ b/tobago-core/src/main/java/org/apache/myfaces/tobago/internal/taglib/declaration/HasAutocomplete.java
@@ -25,6 +25,6 @@ import org.apache.myfaces.tobago.apt.annotation.UIComponentTagAttribute;
public interface HasAutocomplete {
@TagAttribute
- @UIComponentTagAttribute(type = "boolean", defaultValue = "true")
+ @UIComponentTagAttribute(type = {"java.lang.Boolean", "java.lang.String"})
void setAutocomplete(String action);
}
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRendererUnitTest.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRendererUnitTest.java
index 9fc48ab5de..7b05c766fc 100644
--- a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRendererUnitTest.java
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/InRendererUnitTest.java
@@ -543,4 +543,15 @@ public class InRendererUnitTest extends RendererTestBase {
Assertions.assertEquals(loadHtml("renderer/in/required-label-segmentRight.html"), formattedResult());
}
+
+ @Test
+ public void autocompleteTrue() throws IOException {
+
+ final UIIn c = (UIIn) ComponentUtils.createComponent(
+ facesContext, Tags.in.componentType(), RendererTypes.In, "id");
+ c.setAutocomplete(true);
+ c.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/in/autocomplete-on.html"), formattedResult());
+ }
}
diff --git a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TextareaRendererUnitTest.java b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TextareaRendererUnitTest.java
index 2502e3fd99..191aceeea0 100644
--- a/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TextareaRendererUnitTest.java
+++ b/tobago-core/src/test/java/org/apache/myfaces/tobago/internal/renderkit/renderer/TextareaRendererUnitTest.java
@@ -40,4 +40,14 @@ public class TextareaRendererUnitTest extends RendererTestBase {
Assertions.assertEquals(loadHtml("renderer/textarea/with-label.html"), formattedResult());
}
+ @Test
+ public void autocomplete() throws IOException {
+ final UITextarea c = (UITextarea) ComponentUtils.createComponent(
+ facesContext, Tags.textarea.componentType(), RendererTypes.Textarea, "id");
+ c.setAutocomplete("impp");
+ c.encodeAll(facesContext);
+
+ Assertions.assertEquals(loadHtml("renderer/textarea/autocomplete-impp.html"), formattedResult());
+ }
+
}
diff --git a/tobago-core/src/test/resources/renderer/in/autocomplete-on.html b/tobago-core/src/test/resources/renderer/in/autocomplete-on.html
new file mode 100644
index 0000000000..076a9cd014
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/in/autocomplete-on.html
@@ -0,0 +1,20 @@
+<!--
+ * 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.
+-->
+
+<tobago-in id='id' class='tobago-auto-spacing'>
+ <input type='text' name='id' id='id::field' autocomplete='on' class='form-control'>
+</tobago-in>
diff --git a/tobago-core/src/test/resources/renderer/textarea/autocomplete-impp.html b/tobago-core/src/test/resources/renderer/textarea/autocomplete-impp.html
new file mode 100644
index 0000000000..177e59a0fb
--- /dev/null
+++ b/tobago-core/src/test/resources/renderer/textarea/autocomplete-impp.html
@@ -0,0 +1,20 @@
+<!--
+ * 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.
+-->
+
+<tobago-textarea id='id' class='tobago-auto-spacing'>
+ <textarea name='id' id='id::field' autocomplete='impp' class='form-control'></textarea>
+</tobago-textarea>
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/010-input/10-in/In.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/010-input/10-in/In.xhtml
index 832264f151..74608df3c2 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/010-input/10-in/In.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/010-input/10-in/In.xhtml
@@ -71,6 +71,18 @@
<tc:in id="i7" label="Placeholder" placeholder="Short description of the field." />
</tc:section>
+ <tc:section label="Autocomplete">
+ <p>The <code>autocomplete</code> attribute can be used for explaining a user the meaning of a field.</p>
+
+ <tc:in id="a1" label="on" autocomplete="true" />
+ <tc:in id="a2" label="off" autocomplete="false" />
+ <tc:in id="a3" label="name" autocomplete="name" />
+
+ The values are documented in
+ <tc:link label="MDN" image="bi-box-arrow-up-right"
+ link="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#values"/>.
+ </tc:section>
+
<tc:section label="Ajax">
<p>The output field in this example, displays the given value on the server.
With <code class="language-markup"><f:ajax render="outputAjax" listener="\#{inController.update}"/></code>,
diff --git a/tobago-example/tobago-example-demo/src/main/webapp/content/010-input/30-textarea/Textarea.xhtml b/tobago-example/tobago-example-demo/src/main/webapp/content/010-input/30-textarea/Textarea.xhtml
index 65551719ab..0c6fce9ed2 100644
--- a/tobago-example/tobago-example-demo/src/main/webapp/content/010-input/30-textarea/Textarea.xhtml
+++ b/tobago-example/tobago-example-demo/src/main/webapp/content/010-input/30-textarea/Textarea.xhtml
@@ -56,6 +56,18 @@
<tc:button label="Submit" action="#{textareaController.submit}"/>
</tc:section>
+ <tc:section label="Autocomplete">
+ <p>The <code>autocomplete</code> attribute can be used for explaining a user the meaning of a field.</p>
+
+ <tc:textarea id="a1" label="on" autocomplete="true" />
+ <tc:textarea id="a2" label="off" autocomplete="false" />
+ <tc:textarea id="a3" label="name" autocomplete="name" />
+
+ The values are documented in
+ <tc:link label="MDN" image="bi-box-arrow-up-right"
+ link="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete#values"/>.
+ </tc:section>
+
<tc:section label="Ajax">
<p>Ajax update by the change event:</p>
<tc:textarea id="tajax" label="Text Area" value="#{textareaController.ajaxValue}">