Search in sources :

Example 11 with BrowserSniffer

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

the class AlloyRendererCommon method encodeJavaScriptBegin.

/* package-private */
static void encodeJavaScriptBegin(FacesContext facesContext, UIComponent uiComponent, AlloyRenderer alloyRenderer, String[] modules, boolean sandboxed) throws IOException {
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    if (sandboxed) {
        String yuiConfig = alloyRenderer.getYUIConfig(facesContext, responseWriter, uiComponent);
        BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
        String alloyBeginScript = AlloyRendererUtil.getAlloyBeginScript(modules, yuiConfig, browserSniffer);
        responseWriter.write(alloyBeginScript);
    }
    if (facesContext.getPartialViewContext().isAjaxRequest() && (uiComponent instanceof ClientComponent)) {
        ClientComponent clientComponent = (ClientComponent) uiComponent;
        String clientVarName = alloyRenderer.getClientVarName(facesContext, clientComponent);
        String clientKey = clientComponent.getClientKey();
        if (clientKey == null) {
            clientKey = clientVarName;
        }
        encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
        responseWriter.write("if(");
        responseWriter.write(clientVarName);
        responseWriter.write("){");
        responseWriter.write(clientVarName);
        responseWriter.write(".destroy();}");
    }
}
Also used : BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) ResponseWriter(javax.faces.context.ResponseWriter) BufferedScriptResponseWriter(com.liferay.faces.util.render.BufferedScriptResponseWriter) ClientComponent(com.liferay.faces.util.component.ClientComponent)

Example 12 with BrowserSniffer

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

the class InputDateRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    InputDate inputDate = (InputDate) uiComponent;
    String showOn = inputDate.getShowOn();
    if (isNative(browserSniffer, inputDate) || "button".equals(showOn)) {
        String clientVarName = getClientVarName(facesContext, inputDate);
        String clientKey = inputDate.getClientKey();
        if (clientKey == null) {
            clientKey = clientVarName;
        }
        JavaScriptFragment liferayComponent = new JavaScriptFragment("Liferay.component('" + clientKey + "')");
        ResponseWriter responseWriter = facesContext.getResponseWriter();
        if (isNative(browserSniffer, inputDate)) {
            String clientId = uiComponent.getClientId(facesContext);
            String inputClientId = clientId.concat(INPUT_SUFFIX);
            Object maxDateObject = inputDate.getMaxDate();
            Object minDateObject = inputDate.getMinDate();
            String maxDateString = null;
            String minDateString = null;
            if ((maxDateObject != null) || (minDateObject != null)) {
                String datePattern = inputDate.getPattern();
                String timeZoneString = inputDate.getTimeZone();
                TimeZone timeZone = TimeZone.getTimeZone(timeZoneString);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(InputDate.DEFAULT_HTML5_DATE_PATTERN, Locale.ENGLISH);
                if (maxDateObject != null) {
                    Date maxDate = inputDate.getObjectAsDate(maxDateObject, datePattern, timeZone);
                    maxDateString = simpleDateFormat.format(maxDate);
                }
                if (maxDateObject != null) {
                    Date minDate = inputDate.getObjectAsDate(minDateObject, datePattern, timeZone);
                    minDateString = simpleDateFormat.format(minDate);
                }
            }
            encodeFunctionCall(responseWriter, "LFAI.initDateTimePickerMobile", liferayComponent, inputClientId, maxDateString, minDateString);
        } else if ("button".equals(showOn)) {
            String clientId = inputDate.getClientId(facesContext);
            String inputClientId = clientId.concat(INPUT_SUFFIX);
            EscapedClientId escapedInputClientId = new EscapedClientId(inputClientId);
            encodeFunctionCall(responseWriter, "LFAI.initDatePickerShowOnButton", 'A', escapedInputClientId, liferayComponent);
        }
    }
}
Also used : InputDate(com.liferay.faces.alloy.component.inputdate.InputDate) BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) TimeZone(java.util.TimeZone) ResponseWriter(javax.faces.context.ResponseWriter) InputDateTimeResponseWriter(com.liferay.faces.alloy.component.inputdatetime.internal.InputDateTimeResponseWriter) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) EscapedClientId(com.liferay.faces.alloy.render.internal.EscapedClientId) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) InputDate(com.liferay.faces.alloy.component.inputdate.InputDate)

Example 13 with BrowserSniffer

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

the class InputDateRenderer method encodeHiddenAttributes.

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

Example 14 with BrowserSniffer

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

the class InputDateTimeRenderer method encodeMarkupBegin.

@Override
public void encodeMarkupBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // Start the encoding of the outermost <div> element.
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    String clientId = uiComponent.getClientId(facesContext);
    responseWriter.startElement("div", uiComponent);
    // Encode the "id" attribute on the outermost <div> element.
    responseWriter.writeAttribute("id", clientId, "id");
    // Encode the "class" and "style" attributes on the outermost <div> element.
    RendererUtil.encodeStyleable(responseWriter, (Styleable) uiComponent);
    // Start the encoding of the text input by delegating to the renderer from the JSF runtime.
    String inputClientId = clientId.concat(INPUT_SUFFIX);
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    InputDateTime inputDateTime = (InputDateTime) uiComponent;
    InputDateTimeResponseWriter inputDateTimeResponseWriter = getInputDateTimeResponseWriter(responseWriter, inputClientId, isNative(browserSniffer, inputDateTime));
    super.encodeMarkupBegin(facesContext, uiComponent, inputDateTimeResponseWriter);
}
Also used : BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) ResponseWriter(javax.faces.context.ResponseWriter) InputDateTime(com.liferay.faces.alloy.component.inputdatetime.InputDateTime)

Example 15 with BrowserSniffer

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

the class MediaRenderer method encodeFlashPlayer.

protected void encodeFlashPlayer(FacesContext facesContext, ResponseWriter responseWriter, Media media, String mediaResourceURL) throws IOException {
    BrowserSniffer browserSniffer = BrowserSnifferFactory.getBrowserSnifferInstance(facesContext.getExternalContext());
    boolean browserIE = browserSniffer.isIe();
    responseWriter.startElement("object", null);
    encodeMediaSize(responseWriter, media);
    Application application = facesContext.getApplication();
    ResourceHandler resourceHandler = application.getResourceHandler();
    Object flashPlayer = media.getFlashPlayer();
    String flashPlayerURL;
    // If the developer has specified a Flash player, then
    if (flashPlayer != null) {
        flashPlayerURL = getEncodedResourceURL(facesContext, resourceHandler, application, flashPlayer);
    } else // Otherwise, get the default Alloy Flash player.
    {
        Resource defaultFlashPlayerResource = resourceHandler.createResource(getDefaultFlashPlayerName(), "liferay-faces-alloy");
        String defaultFlashPlayerRequestPath = defaultFlashPlayerResource.getRequestPath();
        ExternalContext externalContext = facesContext.getExternalContext();
        flashPlayerURL = externalContext.encodeResourceURL(defaultFlashPlayerRequestPath);
    }
    if (browserIE) {
        responseWriter.writeAttribute("classid", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", null);
        String flashPlayerVersion = media.getFlashPlayerVersion();
        String codebaseURL = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=".concat(flashPlayerVersion);
        responseWriter.writeAttribute("codebase", codebaseURL, null);
        responseWriter.startElement("param", null);
        responseWriter.writeAttribute("name", "movie", null);
        responseWriter.writeAttribute("value", flashPlayerURL, null);
        responseWriter.endElement("param");
    } else {
        responseWriter.writeAttribute("data", flashPlayerURL, null);
        responseWriter.writeAttribute("type", "application/x-shockwave-flash", null);
    }
    encodeFlashPlayerChildren(facesContext, responseWriter, media, mediaResourceURL, resourceHandler, application, (flashPlayer == null));
    responseWriter.endElement("object");
}
Also used : BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) ExternalContext(javax.faces.context.ExternalContext) Resource(javax.faces.application.Resource) FacesResource(com.liferay.faces.util.application.FacesResource) ResourceHandler(javax.faces.application.ResourceHandler) Application(javax.faces.application.Application)

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