Skip to content

Commit

Permalink
Clockpicker add more standard PF features
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Jan 28, 2024
1 parent ed9dcf9 commit 6b114a7
Show file tree
Hide file tree
Showing 9 changed files with 574 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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";
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -442,4 +463,4 @@ public Object saveState(FacesContext context) {

return super.saveState(context);
}
}
}
Loading

0 comments on commit 6b114a7

Please sign in to comment.