Search in sources :

Example 1 with ApplicationFactory

use of javax.faces.application.ApplicationFactory 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 ApplicationFactory

use of javax.faces.application.ApplicationFactory in project empire-db by apache.

the class WebApplication method init.

/**
 * Init the Application
 * @param servletContext
 */
public final void init(FacesImplementation facesImpl, FacesContext startupContext) {
    // Only call once!
    if (this.facesImpl != null || this.webRoot != null) {
        // already initialized
        log.warn("WARNING: WebApplication has already been initialized! Continuing without init...");
        return;
    }
    // set imppl
    this.facesImpl = facesImpl;
    // webRoot
    ServletContext servletContext = (ServletContext) startupContext.getExternalContext().getContext();
    webRoot = servletContext.getContextPath();
    servletContext.setAttribute("webRoot", webRoot);
    servletContext.setAttribute("app", this);
    // Init
    init(servletContext);
    // text resolvers
    log.info("*** initTextResolvers() ***");
    ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    Application app = appFactory.getApplication();
    initTextResolvers(app);
    // Log info
    log.info("*** WebApplication initialization complete ***");
    log.info("JSF-Implementation is '{}'", facesImpl.getClass().getName());
    log.info("WebRoot is '{}'", webRoot);
}
Also used : ServletContext(javax.servlet.ServletContext) ApplicationFactory(javax.faces.application.ApplicationFactory) Application(javax.faces.application.Application)

Example 3 with ApplicationFactory

use of javax.faces.application.ApplicationFactory in project deltaspike by apache.

the class MockedJsf2TestContainer method initApplication.

protected void initApplication() {
    ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTORY);
    this.application = applicationFactory.getApplication();
}
Also used : MockApplicationFactory(org.apache.myfaces.test.mock.MockApplicationFactory) ApplicationFactory(javax.faces.application.ApplicationFactory)

Aggregations

ApplicationFactory (javax.faces.application.ApplicationFactory)3 Application (javax.faces.application.Application)2 Button (com.liferay.faces.alloy.component.button.Button)1 Icon (com.liferay.faces.alloy.component.icon.Icon)1 InputDateTime (com.liferay.faces.alloy.component.inputdatetime.InputDateTime)1 BrowserSniffer (com.liferay.faces.util.client.BrowserSniffer)1 UIComponent (javax.faces.component.UIComponent)1 ResponseWriter (javax.faces.context.ResponseWriter)1 ServletContext (javax.servlet.ServletContext)1 MockApplicationFactory (org.apache.myfaces.test.mock.MockApplicationFactory)1