From f7c15e950309e281eec4bb3ec0b77e5f039b0200 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 27 Nov 2016 19:38:18 +0300 Subject: [PATCH] add proper converter support to DatePicker fixes #558 --- .../bootsfaces/component/datePicker/DatePicker.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/bootsfaces/component/datePicker/DatePicker.java b/src/main/java/net/bootsfaces/component/datePicker/DatePicker.java index 070a46bde..fe342f958 100644 --- a/src/main/java/net/bootsfaces/component/datePicker/DatePicker.java +++ b/src/main/java/net/bootsfaces/component/datePicker/DatePicker.java @@ -350,7 +350,7 @@ private void encodeHTML(FacesContext fc) throws IOException { String styleClass = new CoreRenderer().getErrorAndRequiredClass(this, clientId); rw.writeAttribute("class", "form-control " + styleClass, "class"); if (v != null) { - rw.writeAttribute("value", getDateAsString(v, sdf, sloc), null); + rw.writeAttribute("value", getConvertedDateAsString(v, sdf, sloc), null); } String ph = A.asString(attrs.get("placeholder")); @@ -426,10 +426,10 @@ private void encodeJS(FacesContext fc, ResponseWriter rw, String cId, String dpI * Attributes that need decoding the Date */ if (attrs.get(JQ.MINDATE) != null) { - sb.append(JQ.MINDATE + ":" + "'").append(getDateAsString(attrs.get(JQ.MINDATE), sdf, sloc)).append("',"); + sb.append(JQ.MINDATE + ":" + "'").append(getConvertedDateAsString(attrs.get(JQ.MINDATE), sdf, sloc)).append("',"); } if (attrs.get(JQ.MAXDATE) != null) { - sb.append(JQ.MAXDATE + ":" + "'").append(getDateAsString(attrs.get(JQ.MAXDATE), sdf, sloc)).append("',"); + sb.append(JQ.MAXDATE + ":" + "'").append(getConvertedDateAsString(attrs.get(JQ.MAXDATE), sdf, sloc)).append("',"); } // If user specifies a specific language to use then we render the @@ -446,6 +446,12 @@ private void encodeJS(FacesContext fc, ResponseWriter rw, String cId, String dpI JQ.datePicker(rw, cId, dpId, options, l); } + private String getConvertedDateAsString(Object dt, String format, Locale locale) { + + Converter converter = getConverter(); + return converter == null ? getDateAsString(dt, format, locale) : converter.getAsString(getFacesContext(), this, dt); + } + public static String getDateAsString(Object dt, String format, Locale locale) { if (dt == null) { return null;