Skip to content

Commit

Permalink
add proper converter support to DatePicker
Browse files Browse the repository at this point in the history
fixes #558
  • Loading branch information
Andrew authored and zhedar committed Nov 27, 2016
1 parent a03bd62 commit f7c15e9
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit f7c15e9

Please sign in to comment.