Search in sources :

Example 1 with DateTimeConverter

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 + "')";
                }
            });
        }
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ResponseWriter(javax.faces.context.ResponseWriter) UIComponent(javax.faces.component.UIComponent) DefaultDateBusinessConverter(org.apache.myfaces.custom.calendar.DefaultDateBusinessConverter) DateBusinessConverter(org.apache.myfaces.custom.calendar.DateBusinessConverter) DateTimeConverter(javax.faces.convert.DateTimeConverter) Converter(javax.faces.convert.Converter) DateTimeConverter(javax.faces.convert.DateTimeConverter) FunctionCallProvider(org.apache.myfaces.custom.calendar.FunctionCallProvider) HtmlInputTextHelp(org.apache.myfaces.custom.inputTextHelp.HtmlInputTextHelp) UIInput(javax.faces.component.UIInput) Application(javax.faces.application.Application)

Example 2 with DateTimeConverter

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;
}
Also used : Locale(java.util.Locale) TimeZone(java.util.TimeZone) DateTimeConverter(javax.faces.convert.DateTimeConverter) Converter(javax.faces.convert.Converter) DateTimeConverter(javax.faces.convert.DateTimeConverter)

Aggregations

Converter (javax.faces.convert.Converter)2 DateTimeConverter (javax.faces.convert.DateTimeConverter)2 Locale (java.util.Locale)1 TimeZone (java.util.TimeZone)1 Application (javax.faces.application.Application)1 UIComponent (javax.faces.component.UIComponent)1 UIInput (javax.faces.component.UIInput)1 FacesContext (javax.faces.context.FacesContext)1 ResponseWriter (javax.faces.context.ResponseWriter)1 DateBusinessConverter (org.apache.myfaces.custom.calendar.DateBusinessConverter)1 DefaultDateBusinessConverter (org.apache.myfaces.custom.calendar.DefaultDateBusinessConverter)1 FunctionCallProvider (org.apache.myfaces.custom.calendar.FunctionCallProvider)1 HtmlInputTextHelp (org.apache.myfaces.custom.inputTextHelp.HtmlInputTextHelp)1