From 6b114a723ae66508262ef495399eb5bfb7a525c6 Mon Sep 17 00:00:00 2001 From: melloware Date: Sun, 28 Jan 2024 10:27:25 -0500 Subject: [PATCH] Clockpicker add more standard PF features --- .../component/clockpicker/ClockPicker.java | 25 +- .../clockpicker/ClockPickerRenderer.java | 10 +- .../component/timepicker/TimePicker.java | 25 +- .../META-INF/primefaces-extensions.taglib.xml | 464 +++++++++++++++++- .../clockpicker/1-clockpicker-widget.js | 30 +- .../sections/clockpicker/basicUsage.xhtml | 4 +- .../clockpicker/example-basicUsage.xhtml | 34 +- .../timePicker/example-basicUsage.xhtml | 8 +- .../src/main/webapp/views/clockpicker.xhtml | 11 +- 9 files changed, 574 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/org/primefaces/extensions/component/clockpicker/ClockPicker.java b/core/src/main/java/org/primefaces/extensions/component/clockpicker/ClockPicker.java index 507f293b8..a9e629a27 100644 --- a/core/src/main/java/org/primefaces/extensions/component/clockpicker/ClockPicker.java +++ b/core/src/main/java/org/primefaces/extensions/component/clockpicker/ClockPicker.java @@ -22,8 +22,9 @@ package org.primefaces.extensions.component.clockpicker; import javax.faces.application.ResourceDependency; -import javax.faces.component.html.HtmlInputText; +import org.primefaces.component.api.AbstractPrimeHtmlInputText; +import org.primefaces.component.api.InputHolder; import org.primefaces.component.api.Widget; @ResourceDependency(library = "primefaces", name = "components.css") @@ -32,7 +33,7 @@ @ResourceDependency(library = "primefaces", name = "core.js") @ResourceDependency(library = "primefaces-extensions", name = "clockpicker/clockpicker.css") @ResourceDependency(library = "primefaces-extensions", name = "clockpicker/clockpicker.js") -public class ClockPicker extends HtmlInputText implements Widget { +public class ClockPicker extends AbstractPrimeHtmlInputText implements Widget, InputHolder { public static final String CONTAINER_CLASS = "pe-clockpicker ui-widget ui-corner-all input-group clockpicker"; public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.ClockPicker"; @@ -57,6 +58,26 @@ public ClockPicker() { public String getFamily() { return COMPONENT_FAMILY; } + + @Override + public String getInputClientId() { + return getClientId(getFacesContext()) + "_input"; + } + + @Override + public String getValidatableInputClientId() { + return getInputClientId(); + } + + @Override + public String getLabelledBy() { + return (String) getStateHelper().get("labelledby"); + } + + @Override + public void setLabelledBy(String labelledBy) { + getStateHelper().put("labelledby", labelledBy); + } public String getWidgetVar() { return (String) getStateHelper().eval(PropertyKeys.widgetVar, null); diff --git a/core/src/main/java/org/primefaces/extensions/component/clockpicker/ClockPickerRenderer.java b/core/src/main/java/org/primefaces/extensions/component/clockpicker/ClockPickerRenderer.java index 0843992a7..2385ae952 100644 --- a/core/src/main/java/org/primefaces/extensions/component/clockpicker/ClockPickerRenderer.java +++ b/core/src/main/java/org/primefaces/extensions/component/clockpicker/ClockPickerRenderer.java @@ -33,11 +33,12 @@ import javax.faces.convert.Converter; import javax.faces.convert.ConverterException; -import org.primefaces.renderkit.CoreRenderer; +import org.primefaces.renderkit.InputRenderer; +import org.primefaces.util.HTML; import org.primefaces.util.LangUtils; import org.primefaces.util.WidgetBuilder; -public class ClockPickerRenderer extends CoreRenderer { +public class ClockPickerRenderer extends InputRenderer { private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("HH:mm"); @@ -87,6 +88,11 @@ private void encodeMarkup(FacesContext context, ClockPicker clockPicker, final S writer.writeAttribute("value", value, null); } + renderAccessibilityAttributes(context, clockPicker); + renderPassThruAttributes(context, clockPicker, HTML.INPUT_TEXT_ATTRS_WITHOUT_EVENTS); + renderDomEvents(context, clockPicker, HTML.INPUT_TEXT_EVENTS); + renderValidationMetadata(context, clockPicker); + writer.endElement("input"); writer.startElement("span", null); diff --git a/core/src/main/java/org/primefaces/extensions/component/timepicker/TimePicker.java b/core/src/main/java/org/primefaces/extensions/component/timepicker/TimePicker.java index 7331a8f32..79cae91ea 100644 --- a/core/src/main/java/org/primefaces/extensions/component/timepicker/TimePicker.java +++ b/core/src/main/java/org/primefaces/extensions/component/timepicker/TimePicker.java @@ -34,6 +34,7 @@ import javax.faces.event.PhaseId; import org.primefaces.component.api.AbstractPrimeHtmlInputText; +import org.primefaces.component.api.InputHolder; import org.primefaces.component.api.Widget; import org.primefaces.extensions.event.BeforeShowEvent; import org.primefaces.extensions.event.CloseEvent; @@ -56,7 +57,7 @@ @ResourceDependency(library = "primefaces-extensions", name = "primefaces-extensions.js") @ResourceDependency(library = "primefaces-extensions", name = "timepicker/timepicker.css") @ResourceDependency(library = "primefaces-extensions", name = "timepicker/timepicker.js") -public class TimePicker extends AbstractPrimeHtmlInputText implements Widget { +public class TimePicker extends AbstractPrimeHtmlInputText implements Widget, InputHolder { public static final String CONTAINER_CLASS = "pe-timepicker ui-widget ui-corner-all"; public static final String INPUT_CLASS = "ui-inputfield ui-state-default ui-corner-all"; @@ -125,6 +126,26 @@ public String getFamily() { return COMPONENT_FAMILY; } + @Override + public String getInputClientId() { + return getClientId(getFacesContext()) + "_input"; + } + + @Override + public String getValidatableInputClientId() { + return getInputClientId(); + } + + @Override + public String getLabelledBy() { + return (String) getStateHelper().get("labelledby"); + } + + @Override + public void setLabelledBy(String labelledBy) { + getStateHelper().put("labelledby", labelledBy); + } + public String getWidgetVar() { return (String) getStateHelper().eval(PropertyKeys.widgetVar, null); } @@ -442,4 +463,4 @@ public Object saveState(FacesContext context) { return super.saveState(context); } -} +} \ No newline at end of file diff --git a/core/src/main/resources/META-INF/primefaces-extensions.taglib.xml b/core/src/main/resources/META-INF/primefaces-extensions.taglib.xml index 03aae523f..476e84286 100755 --- a/core/src/main/resources/META-INF/primefaces-extensions.taglib.xml +++ b/core/src/main/resources/META-INF/primefaces-extensions.taglib.xml @@ -10422,26 +10422,482 @@ See showcase for an example. Default null.]]> org.primefaces.extensions.component.ClockPickerRenderer - + + + id false java.lang.String - + + + rendered false java.lang.Boolean - + + + + binding + false + javax.faces.component.UIComponent + + + + value false java.lang.Object - + + + + converter + false + java.faces.convert.Converter + + + + + + immediate + false + java.lang.Boolean + + + + + + required + false + java.lang.Boolean + + + + + + validator + false + javax.faces.validator.Validator + + + + + + valueChangeListener + false + javax.faces.event.ValueChangeListener + + + + + + requiredMessage + false + java.lang.String + + + + + + converterMessage + false + java.lang.String + + + + + + validatorMessage + false + java.lang.String + + + + + + accesskey + false + java.lang.String + + + + + + alt + false + java.lang.String + + + + + + autocomplete + false + java.lang.String + + + + + + dir + false + java.lang.String + + + + + + disabled + false + boolean + + + + + + inputmode + false + java.lang.String + + + + + + label + false + java.lang.String + + + + + + lang + false + java.lang.String + + + + + + maxlength + false + int + + + + + + onblur + false + java.lang.String + + + + + + onchange + false + java.lang.String + + + + + + onclick + false + java.lang.String + + + + + + ondblclick + false + java.lang.String + + + + + + onfocus + false + java.lang.String + + + + + + onkeydown + false + java.lang.String + + + + + + onkeypress + false + java.lang.String + + + + + + onkeyup + false + java.lang.String + + + + + + onmousedown + false + java.lang.String + + + + + + onmousemove + false + java.lang.String + + + + + + onmouseout + false + java.lang.String + + + + + + onmouseover + false + java.lang.String + + + + + + onmouseup + false + java.lang.String + + + + + + onwheel + false + java.lang.String + + + + + + onselect + false + java.lang.String + + + + + + oncut + false + java.lang.String + + + + + + oncopy + false + java.lang.String + + + + + + onpaste + false + java.lang.String + + + + + + oninput + false + java.lang.String + + + + + + oncontextmenu + false + java.lang.String + + + + + + oninvalid + false + java.lang.String + + + + + + onreset + false + java.lang.String + + + + + + onsearch + false + java.lang.String + + + + + + ondrag + false + java.lang.String + + + + + + ondragend + false + java.lang.String + + + + + + ondragenter + false + java.lang.String + + + + + + ondragleave + false + java.lang.String + + + + + + ondragover + false + java.lang.String + + + + + + ondragstart + false + java.lang.String + + + + + + ondrop + false + java.lang.String + + + + + + onscroll + false + java.lang.String + + + + + + readonly + false + boolean + + + + + + size + false + int + + + + + + style + false + java.lang.String + + + + + + styleClass + false + java.lang.String + + + + + + tabindex + false + java.lang.String + + + + + + title + false + java.lang.String + + + + + + placeholder + false + java.lang.String + + + + + widgetVar false java.lang.String diff --git a/core/src/main/resources/META-INF/resources/primefaces-extensions/clockpicker/1-clockpicker-widget.js b/core/src/main/resources/META-INF/resources/primefaces-extensions/clockpicker/1-clockpicker-widget.js index 7721b707d..a5c9f39d6 100644 --- a/core/src/main/resources/META-INF/resources/primefaces-extensions/clockpicker/1-clockpicker-widget.js +++ b/core/src/main/resources/META-INF/resources/primefaces-extensions/clockpicker/1-clockpicker-widget.js @@ -19,7 +19,7 @@ PrimeFaces.widget.ExtClockPicker = PrimeFaces.widget.BaseWidget.extend({ this.clockpicker = this.jq.clockpicker(this.cfg); // pfs metadata - $(this.jqId + '_input').data(PrimeFaces.CLIENT_ID_DATA, this.id); + this.jq.data(PrimeFaces.CLIENT_ID_DATA, this.id); this.originalValue = this.jq.val(); }, @@ -46,8 +46,8 @@ PrimeFaces.widget.ExtClockPicker = PrimeFaces.widget.BaseWidget.extend({ * @function hide */ hide: function () { - if (this.clockpicker) { - this.clockpicker.hide() + if (this.jq) { + this.jq.clockpicker("hide"); } }, @@ -56,8 +56,8 @@ PrimeFaces.widget.ExtClockPicker = PrimeFaces.widget.BaseWidget.extend({ * @function show */ show: function () { - if (this.clockpicker) { - this.clockpicker.show() + if (this.jq) { + this.jq.clockpicker("show"); } }, /** @@ -65,8 +65,24 @@ PrimeFaces.widget.ExtClockPicker = PrimeFaces.widget.BaseWidget.extend({ * @function remove */ remove: function () { - if (this.clockpicker) { - this.clockpicker.remove() + if (this.jq) { + this.jq.clockpicker("remove"); } + }, + + /** + * Disables this input so that the user cannot enter a value anymore. + */ + disable: function() { + this.remove(); + PrimeFaces.utils.disableInputWidget(this.jq); + }, + + /** + * Enables this input so that the user can enter a value. + */ + enable: function() { + PrimeFaces.utils.enableInputWidget(this.jq); + this.clockpicker = this.jq.clockpicker(this.cfg); } }); \ No newline at end of file diff --git a/showcase/src/main/webapp/sections/clockpicker/basicUsage.xhtml b/showcase/src/main/webapp/sections/clockpicker/basicUsage.xhtml index e9076d2d3..f1d908b4a 100644 --- a/showcase/src/main/webapp/sections/clockpicker/basicUsage.xhtml +++ b/showcase/src/main/webapp/sections/clockpicker/basicUsage.xhtml @@ -9,7 +9,7 @@ - clockpicker + ClockPicker is a clock-style timepicker. @@ -34,4 +34,4 @@ ${showcase:getFileContent('/org/primefaces/extensions/showcase/controller/ClockP - + \ No newline at end of file diff --git a/showcase/src/main/webapp/sections/clockpicker/example-basicUsage.xhtml b/showcase/src/main/webapp/sections/clockpicker/example-basicUsage.xhtml index 6b8b66ca6..220dd27c7 100644 --- a/showcase/src/main/webapp/sections/clockpicker/example-basicUsage.xhtml +++ b/showcase/src/main/webapp/sections/clockpicker/example-basicUsage.xhtml @@ -1,18 +1,30 @@ + xmlns:ui="http://xmlns.jcp.org/jsf/facelets" xmlns:p="http://primefaces.org/ui" + xmlns:pe="http://primefaces.org/ui/extensions"> - - + + - -
- - -
+ + +

Auto-Close Mode

+ - - +

Manual Close Mode

+ + +
+ + + + + +
\ No newline at end of file diff --git a/showcase/src/main/webapp/sections/timePicker/example-basicUsage.xhtml b/showcase/src/main/webapp/sections/timePicker/example-basicUsage.xhtml index 8a4019e3a..cc85ac385 100644 --- a/showcase/src/main/webapp/sections/timePicker/example-basicUsage.xhtml +++ b/showcase/src/main/webapp/sections/timePicker/example-basicUsage.xhtml @@ -47,17 +47,17 @@

- - + styleClass="mt-2 mr-2" icon="pi pi-save"/> @@ -70,4 +70,4 @@ - + \ No newline at end of file diff --git a/showcase/src/main/webapp/views/clockpicker.xhtml b/showcase/src/main/webapp/views/clockpicker.xhtml index 154c628e6..3d82451be 100644 --- a/showcase/src/main/webapp/views/clockpicker.xhtml +++ b/showcase/src/main/webapp/views/clockpicker.xhtml @@ -8,9 +8,14 @@ - Based on clockpicker by weareoutman. - + + + + ClockPicker is a highly configurable component to integrate time inputs (hours / minutes) in a convenient way. +

+ Based on clockpicker by weareoutman. + @@ -21,4 +26,4 @@ - + \ No newline at end of file