use of javax.faces.convert.DateTimeConverter in project gdmatrix by gdmatrix.
the class HtmlCalendarRenderer method renderPopup.
private void renderPopup(FacesContext facesContext, HtmlInputCalendar inputCalendar, String value, Calendar timeKeeper, DateFormatSymbols symbols) throws IOException {
if (inputCalendar.isAddResources())
addScriptAndCSSResources(facesContext, inputCalendar);
// Check for an enclosed converter:
UIInput uiInput = (UIInput) inputCalendar;
Converter converter = uiInput.getConverter();
String dateFormat = null;
if (converter != null && converter instanceof DateTimeConverter) {
dateFormat = ((DateTimeConverter) converter).getPattern();
}
if (dateFormat == null) {
dateFormat = CalendarDateTimeConverter.createJSPopupFormat(facesContext, inputCalendar.getPopupDateFormat());
}
Application application = facesContext.getApplication();
HtmlInputTextHelp inputText = getOrCreateInputTextChild(inputCalendar, application);
RendererUtils.copyHtmlInputTextAttributes(inputCalendar, inputText);
// value for this transient component will already be converted
inputText.setConverter(null);
inputText.setTransient(true);
inputText.setHelpText(inputCalendar.getHelpText());
inputText.setSelectText(true);
inputText.setValue(value);
/*
if (value == null && inputCalendar.getSubmittedValue() != null)
{
inputText.setValue(inputCalendar.getSubmittedValue());
}
else
{
inputText.setValue(getConverter(inputCalendar).getAsString(
facesContext,inputCalendar,value));
}*/
inputText.setDisabled(inputCalendar.isDisabled());
inputText.setReadonly(inputCalendar.isReadonly());
inputText.setEnabledOnUserRole(inputCalendar.getEnabledOnUserRole());
inputText.setVisibleOnUserRole(inputCalendar.getVisibleOnUserRole());
// This is where two components with the same id are in the tree,
// so make sure that during the rendering the id is unique.
inputCalendar.setId(inputCalendar.getId() + "tempId");
inputCalendar.getChildren().add(inputText);
RendererUtils.renderChild(facesContext, inputText);
inputCalendar.getChildren().remove(inputText);
// Set back the correct id to the input calendar
inputCalendar.setId(inputText.getId());
ResponseWriter writer = facesContext.getResponseWriter();
writer.startElement(HTML.SPAN_ELEM, inputCalendar);
writer.writeAttribute(HTML.ID_ATTR, inputCalendar.getClientId(facesContext) + "Span", JSFAttr.ID_ATTR);
writer.endElement(HTML.SPAN_ELEM);
if (!isDisabled(facesContext, inputCalendar) && !inputCalendar.isReadonly()) {
writer.startElement(HTML.SCRIPT_ELEM, inputCalendar);
writer.writeAttribute(HTML.SCRIPT_TYPE_ATTR, HTML.SCRIPT_TYPE_TEXT_JAVASCRIPT, null);
String calendarVar = JavascriptUtils.getValidJavascriptName(inputCalendar.getClientId(facesContext) + "CalendarVar", false);
writer.writeText(calendarVar + "=new org_apache_myfaces_PopupCalendar();\n", null);
writer.writeText(getLocalizedLanguageScript(facesContext, symbols, timeKeeper.getFirstDayOfWeek(), inputCalendar, calendarVar) + "\n", null);
// pass the selectMode attribute
StringBuffer script = new StringBuffer();
setStringVariable(script, calendarVar + ".initData.selectMode", inputCalendar.getPopupSelectMode());
writer.writeText(script.toString(), null);
writer.writeText(calendarVar + ".init(document.getElementById('" + inputCalendar.getClientId(facesContext) + "Span" + "'));\n", null);
writer.endElement(HTML.SCRIPT_ELEM);
if (!inputCalendar.isDisplayValueOnly()) {
getScriptBtn(writer, facesContext, inputCalendar, dateFormat, inputCalendar.getPopupButtonString(), new FunctionCallProvider() {
public String getFunctionCall(FacesContext facesContext, UIComponent uiComponent, String dateFormat) {
String clientId = uiComponent.getClientId(facesContext);
String clientVar = JavascriptUtils.getValidJavascriptName(clientId + "CalendarVar", true);
return clientVar + "._popUpCalendar(this,document.getElementById('" + clientId + "'),'" + dateFormat + "')";
}
});
}
}
}
use of javax.faces.convert.DateTimeConverter in project liferay-faces-alloy by liferay.
the class InputDateTime method getConverter.
@Override
public Converter getConverter() {
Converter converter = super.getConverter();
if (converter == null) {
// Provide a default converter of DateTimeConverter if no converter is specified.
DateTimeConverter dateTimeConverter = new DateTimeConverter();
String pattern = getPattern();
dateTimeConverter.setPattern(pattern);
Object objectLocale = getLocale();
Locale locale = getObjectAsLocale(objectLocale);
dateTimeConverter.setLocale(locale);
String timeZoneString = getTimeZone();
TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
dateTimeConverter.setTimeZone(timeZone);
converter = dateTimeConverter;
}
return converter;
}
Aggregations