Search in sources :

Example 6 with BrowserSniffer

use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.

the class InputDateTimeRenderer method getModules.

protected String[] getModules(String defaultModule, FacesContext facesContext, UIComponent uiComponent) {
    String[] modules = new String[] { defaultModule };
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    InputDateTime inputDateTime = (InputDateTime) uiComponent;
    if (isNative(browserSniffer, inputDateTime)) {
        modules[0] = defaultModule.concat("-native");
    } else {
        Map<String, List<ClientBehavior>> clientBehaviorMap = inputDateTime.getClientBehaviors();
        List<ClientBehavior> valueChangeClientBehaviors = clientBehaviorMap.get(VALUE_CHANGE);
        if ((valueChangeClientBehaviors != null) && !valueChangeClientBehaviors.isEmpty()) {
            modules = StringHelper.append(modules, NODE_EVENT_SIMULATE);
        }
    }
    return modules;
}
Also used : BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) List(java.util.List) InputDateTime(com.liferay.faces.alloy.component.inputdatetime.InputDateTime) ClientBehavior(javax.faces.component.behavior.ClientBehavior)

Example 7 with BrowserSniffer

use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.

the class InputTime method getPattern.

@Override
public String getPattern() {
    String timePattern;
    FacesContext facesContext = FacesContext.getCurrentInstance();
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    if (browserSniffer.isMobile() && isNativeWhenMobile()) {
        timePattern = DEFAULT_HTML5_TIME_PATTERN;
    } else {
        timePattern = super.getPattern();
    }
    return timePattern;
}
Also used : FacesContext(javax.faces.context.FacesContext) BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer)

Example 8 with BrowserSniffer

use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.

the class InputTimeRenderer method getAlloyClassName.

@Override
public String getAlloyClassName(FacesContext facesContext, UIComponent uiComponent) {
    String alloyClassName = super.getAlloyClassName(facesContext, uiComponent);
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    InputTime inputTime = (InputTime) uiComponent;
    if (isNative(browserSniffer, inputTime)) {
        alloyClassName = alloyClassName.concat("Native");
    }
    return alloyClassName;
}
Also used : BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) InputTime(com.liferay.faces.alloy.component.inputtime.InputTime)

Example 9 with BrowserSniffer

use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.

the class InputTimeRenderer method encodeHiddenAttributes.

@Override
protected void encodeHiddenAttributes(FacesContext facesContext, ResponseWriter responseWriter, InputTime inputTime, boolean first) throws IOException {
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    if (!isNative(browserSniffer, inputTime)) {
        encodeAutocomplete(facesContext, responseWriter, inputTime, first);
        first = false;
        encodeHiddenAttributesInputDateTime(facesContext, responseWriter, inputTime, first);
        first = false;
    }
}
Also used : BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer)

Example 10 with BrowserSniffer

use of com.liferay.faces.util.client.BrowserSniffer in project liferay-faces-alloy by liferay.

the class InputTimeRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    InputTime inputTime = (InputTime) uiComponent;
    String clientVarName = getClientVarName(facesContext, inputTime);
    String clientKey = inputTime.getClientKey();
    if (clientKey == null) {
        clientKey = clientVarName;
    }
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    if (isNative(browserSniffer, inputTime)) {
        JavaScriptFragment liferayComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
        String clientId = uiComponent.getClientId(facesContext);
        String inputClientId = clientId.concat(INPUT_SUFFIX);
        // Get the max and min times in the HTML5 format which does not include seconds.
        int defaultHTML5PatternLength = InputTime.DEFAULT_HTML5_TIME_PATTERN.length();
        String maxTime = inputTime.getMaxTime().substring(0, defaultHTML5PatternLength);
        String minTime = inputTime.getMinTime().substring(0, defaultHTML5PatternLength);
        encodeFunctionCall(responseWriter, "LFAI.initDateTimePickerMobile", liferayComponent, inputClientId, maxTime, minTime);
    } else {
        encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
        // Replace the default TimePicker._setValues() method with setValues() (defined in alloy.js) which simply
        // passes values through to the autocomplete without processing them.
        responseWriter.write(clientVarName);
        responseWriter.write("._setValues=LFAI.timePickerSetValues;");
        // Set the values of the timePicker.
        responseWriter.write(clientVarName);
        responseWriter.write(".set('values',[");
        String minTimeStamp = inputTime.getMinTime();
        String maxTimeStamp = inputTime.getMaxTime();
        long minTime;
        long maxTime;
        try {
            minTime = getMillisFromTimeStamp(minTimeStamp);
            maxTime = getMillisFromTimeStamp(maxTimeStamp);
        } catch (ParseException e) {
            throw new IOException(e);
        }
        if (minTime > maxTime) {
            throw new IOException("minTime must not be later than maxTime.");
        }
        String timePattern = inputTime.getPattern();
        Object objectLocale = inputTime.getLocale();
        Locale locale = inputTime.getObjectAsLocale(objectLocale);
        TimeZone timeZone = TimeZone.getTimeZone("Greenwich");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(timePattern, locale);
        simpleDateFormat.setTimeZone(timeZone);
        Integer millisecondStep = inputTime.getStep() * 1000;
        boolean firstTimeStamp = true;
        if (millisecondStep < 1) {
            throw new IOException("step cannot be less than 1.");
        }
        // step, and printing each resulting value.
        for (long milliseconds = minTime; milliseconds <= maxTime; milliseconds = milliseconds + millisecondStep) {
            if (!firstTimeStamp) {
                responseWriter.write(",");
            } else {
                firstTimeStamp = false;
            }
            Date time = new Date(milliseconds);
            String dateString = simpleDateFormat.format(time);
            String escapedDateString = RendererUtil.escapeJavaScript(dateString);
            responseWriter.write("'");
            responseWriter.write(escapedDateString);
            responseWriter.write("'");
        }
        responseWriter.write("]);");
    }
}
Also used : Locale(java.util.Locale) BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) InputTime(com.liferay.faces.alloy.component.inputtime.InputTime) IOException(java.io.IOException) Date(java.util.Date) TimeZone(java.util.TimeZone) InputDateTimeResponseWriter(com.liferay.faces.alloy.component.inputdatetime.internal.InputDateTimeResponseWriter) ResponseWriter(javax.faces.context.ResponseWriter) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

BrowserSniffer (com.liferay.faces.util.client.BrowserSniffer)15 ResponseWriter (javax.faces.context.ResponseWriter)6 InputDateTime (com.liferay.faces.alloy.component.inputdatetime.InputDateTime)3 InputDate (com.liferay.faces.alloy.component.inputdate.InputDate)2 InputDateTimeResponseWriter (com.liferay.faces.alloy.component.inputdatetime.internal.InputDateTimeResponseWriter)2 InputTime (com.liferay.faces.alloy.component.inputtime.InputTime)2 Script (com.liferay.faces.util.client.Script)2 BufferedScriptResponseWriter (com.liferay.faces.util.render.BufferedScriptResponseWriter)2 JavaScriptFragment (com.liferay.faces.util.render.JavaScriptFragment)2 SimpleDateFormat (java.text.SimpleDateFormat)2 Date (java.util.Date)2 TimeZone (java.util.TimeZone)2 Application (javax.faces.application.Application)2 ExternalContext (javax.faces.context.ExternalContext)2 FacesContext (javax.faces.context.FacesContext)2 Button (com.liferay.faces.alloy.component.button.Button)1 Icon (com.liferay.faces.alloy.component.icon.Icon)1 OutputScript (com.liferay.faces.alloy.component.outputscript.OutputScript)1 EscapedClientId (com.liferay.faces.alloy.render.internal.EscapedClientId)1 FacesResource (com.liferay.faces.util.application.FacesResource)1