Search in sources :

Example 1 with InputDateTime

use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime in project liferay-faces-alloy by liferay.

the class InputDateTimeRenderer method encodeMarkupEnd.

@Override
public void encodeMarkupEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    String clientId = uiComponent.getClientId(facesContext);
    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.encodeMarkupEnd(facesContext, uiComponent, inputDateTimeResponseWriter);
    // Determine whether or not the text input is enabled.
    boolean disabled = inputDateTime.isDisabled();
    // If the "showOn" attribute indicates that a button is to be rendered and the component is not being rendered
    // for a mobile browser, then render the button.
    String showOn = inputDateTime.getShowOn();
    if (("both".equals(showOn) || "button".equals(showOn)) && !isNative(browserSniffer, inputDateTime)) {
        ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
        Application application = applicationFactory.getApplication();
        // Create an icon component that is to remain detached from the component tree.
        Icon icon = (Icon) application.createComponent(Icon.COMPONENT_TYPE);
        String buttonIconName = getButtonIconName();
        icon.setName(buttonIconName);
        // Create a button component that that is also to remain detached from the component tree.
        Button button = (Button) application.createComponent(Button.COMPONENT_TYPE);
        List<UIComponent> buttonChildren = button.getChildren();
        buttonChildren.add(icon);
        button.setDisabled(disabled);
        // If the component is enabled, then
        if (!disabled) {
            if ("button".equals(showOn)) {
                String buttonClientId = getButtonClientId(facesContext, inputDateTime);
                button.setId(buttonClientId);
            } else {
                // If the both the button and the input are supposed to trigger the datePicker, set the button's
                // onclick to focus and click the input.
                String onClick = BUTTON_ON_CLICK_EVENT.replace("{0}", inputClientId);
                button.setOnclick(onClick);
            }
        }
        // Invoke the button's renderer so that it renders itself and its child icon.
        button.encodeAll(facesContext);
    }
    // If the component is enabled, then create the boundingBox and contentBox of the picker.
    if (!disabled) {
        responseWriter.startElement("div", uiComponent);
        String boundingBoxClientId = clientId.concat(BOUNDING_BOX_SUFFIX);
        responseWriter.writeAttribute("id", boundingBoxClientId, null);
        responseWriter.startElement("div", uiComponent);
        String contentBoxClientId = clientId.concat(CONTENT_BOX_SUFFIX);
        responseWriter.writeAttribute("id", contentBoxClientId, null);
        responseWriter.endElement("div");
        responseWriter.endElement("div");
    }
    // Finish the encoding of the outermost </div> element.
    responseWriter.endElement("div");
}
Also used : BrowserSniffer(com.liferay.faces.util.client.BrowserSniffer) ResponseWriter(javax.faces.context.ResponseWriter) Button(com.liferay.faces.alloy.component.button.Button) UIComponent(javax.faces.component.UIComponent) ApplicationFactory(javax.faces.application.ApplicationFactory) Icon(com.liferay.faces.alloy.component.icon.Icon) InputDateTime(com.liferay.faces.alloy.component.inputdatetime.InputDateTime) Application(javax.faces.application.Application)

Example 2 with InputDateTime

use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime in project liferay-faces-alloy by liferay.

the class InputDateTimeRenderer method isSandboxed.

@Override
public boolean isSandboxed(FacesContext facesContext, UIComponent uiComponent) {
    // In order to support the "lang" attribute of the YUI object, it is necessary to determine if the user has
    // specified a locale other than that of the server or view root. If so, then the javascript must be rendered
    // inline.
    InputDateTime inputDateTime = (InputDateTime) uiComponent;
    Locale locale = inputDateTime.getObjectAsLocale(inputDateTime.getLocale(facesContext));
    UIViewRoot viewRoot = facesContext.getViewRoot();
    Locale viewRootLocale = viewRoot.getLocale();
    return !locale.equals(viewRootLocale);
}
Also used : Locale(java.util.Locale) InputDateTime(com.liferay.faces.alloy.component.inputdatetime.InputDateTime) UIViewRoot(javax.faces.component.UIViewRoot)

Example 3 with InputDateTime

use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime 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 4 with InputDateTime

use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime 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 5 with InputDateTime

use of com.liferay.faces.alloy.component.inputdatetime.InputDateTime in project liferay-faces-alloy by liferay.

the class InputDateTimeRenderer method getYUIConfig.

@Override
public String getYUIConfig(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
    InputDateTime inputDateTime = (InputDateTime) uiComponent;
    Locale locale = inputDateTime.getObjectAsLocale(inputDateTime.getLocale(facesContext));
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("{lang:");
    // RFC 1766 requires the subtags of locales to be delimited by hyphens rather than underscores.
    // http://www.faqs.org/rfcs/rfc1766.html
    stringBuilder.append("'");
    String localeString = locale.toString().replaceAll("_", "-");
    stringBuilder.append(localeString);
    stringBuilder.append("'}");
    return stringBuilder.toString();
}
Also used : Locale(java.util.Locale) InputDateTime(com.liferay.faces.alloy.component.inputdatetime.InputDateTime)

Aggregations

InputDateTime (com.liferay.faces.alloy.component.inputdatetime.InputDateTime)5 BrowserSniffer (com.liferay.faces.util.client.BrowserSniffer)3 Locale (java.util.Locale)2 ResponseWriter (javax.faces.context.ResponseWriter)2 Button (com.liferay.faces.alloy.component.button.Button)1 Icon (com.liferay.faces.alloy.component.icon.Icon)1 List (java.util.List)1 Application (javax.faces.application.Application)1 ApplicationFactory (javax.faces.application.ApplicationFactory)1 UIComponent (javax.faces.component.UIComponent)1 UIViewRoot (javax.faces.component.UIViewRoot)1 ClientBehavior (javax.faces.component.behavior.ClientBehavior)1