Search in sources :

Example 1 with DefaultFaceletFactory

use of com.sun.faces.facelets.impl.DefaultFaceletFactory in project mojarra by eclipse-ee4j.

the class ApplicationAssociate method createFaceletFactory.

protected DefaultFaceletFactory createFaceletFactory(FacesContext context, Compiler compiler, WebConfiguration webConfig) {
    // refresh period
    boolean isProduction = applicationImpl.getProjectStage() == Production;
    String refreshPeriod;
    if (webConfig.isSet(FaceletsDefaultRefreshPeriod)) {
        refreshPeriod = webConfig.getOptionValue(FaceletsDefaultRefreshPeriod);
    } else if (isProduction) {
        refreshPeriod = "-1";
    } else {
        refreshPeriod = FaceletsDefaultRefreshPeriod.getDefaultValue();
    }
    long period = parseLong(refreshPeriod);
    // resource resolver
    DefaultResourceResolver resolver = new DefaultResourceResolver(applicationImpl.getResourceHandler());
    FaceletCacheFactory cacheFactory = (FaceletCacheFactory) FactoryFinder.getFactory(FACELET_CACHE_FACTORY);
    FaceletCache<?> cache = cacheFactory.getFaceletCache();
    DefaultFaceletFactory toReturn = new DefaultFaceletFactory();
    toReturn.init(context, compiler, resolver, period, cache);
    return toReturn;
}
Also used : DefaultFaceletFactory(com.sun.faces.facelets.impl.DefaultFaceletFactory) DefaultResourceResolver(com.sun.faces.facelets.impl.DefaultResourceResolver) FaceletCacheFactory(jakarta.faces.view.facelets.FaceletCacheFactory) MessageUtils.getExceptionMessageString(com.sun.faces.util.MessageUtils.getExceptionMessageString)

Example 2 with DefaultFaceletFactory

use of com.sun.faces.facelets.impl.DefaultFaceletFactory in project mojarra by eclipse-ee4j.

the class FaceletViewHandlingStrategy method createComponentMetadata.

private BeanInfo createComponentMetadata(FacesContext context, Resource ccResource) {
    // PENDING this implementation is terribly wasteful.
    // Must find a better way.
    FaceletContext faceletContext = (FaceletContext) context.getAttributes().get(FACELET_CONTEXT_KEY);
    DefaultFaceletFactory factory = (DefaultFaceletFactory) RequestStateManager.get(context, FACELET_FACTORY);
    VariableMapper orig = faceletContext.getVariableMapper();
    // Create tmp and facetComponent
    UIComponent tmp = context.getApplication().createComponent("jakarta.faces.NamingContainer");
    UIPanel facetComponent = (UIPanel) context.getApplication().createComponent("jakarta.faces.Panel");
    // PENDING I think this can be skipped because we don't render
    // this component instance.
    facetComponent.setRendererType("jakarta.faces.Group");
    // PENDING This could possibly be skipped too. However, I think
    // this is important because other tag handlers, within
    // <cc:interface> expect it will be there.
    tmp.getFacets().put(COMPOSITE_FACET_NAME, facetComponent);
    // We have to put the resource in here just so the classes that eventually
    // get called by facelets have access to it.
    tmp.getAttributes().put(COMPONENT_RESOURCE_KEY, ccResource);
    Facelet facelet;
    try {
        facelet = factory.getFacelet(context, ccResource.getURL());
        VariableMapper wrapper = new VariableMapperWrapper(orig) {

            @Override
            public ValueExpression resolveVariable(String variable) {
                // PENDING is this needed?
                return super.resolveVariable(variable);
            }
        };
        faceletContext.setVariableMapper(wrapper);
        context.getAttributes().put(IS_BUILDING_METADATA, TRUE);
        // Because mojarra currently requires a <cc:interface>
        // element within the compcomp markup, we can rely on the
        // fact that its tag handler, InterfaceHandler.apply(), is
        // called. In this method, we first imbue facetComponent
        // with any config information present on the <cc:interface>
        // element.
        // Then we do the normal facelet thing:
        // this.nextHandler.apply(). This causes any child tag
        // handlers of the <cc:interface> to be called. The
        // compcomp spec says each such tag handler is responsible
        // for adding to the compcomp metadata, referenced from the
        // facetComponent parent.
        facelet.apply(context, facetComponent);
    // When facelet.apply() returns (and therefore
    // InterfaceHandler.apply() returns), the compcomp metadata
    // pointed to by facetComponent is fully populated.
    } catch (Exception e) {
        if (e instanceof FacesException) {
            throw (FacesException) e;
        } else {
            throw new FacesException(e);
        }
    } finally {
        context.getAttributes().remove(IS_BUILDING_METADATA);
        faceletContext.setVariableMapper(orig);
    }
    // not yet implemented.
    return (CompositeComponentBeanInfo) tmp.getAttributes().get(BEANINFO_KEY);
}
Also used : DefaultFaceletFactory(com.sun.faces.facelets.impl.DefaultFaceletFactory) Facelet(jakarta.faces.view.facelets.Facelet) CompositeComponentBeanInfo(com.sun.faces.facelets.tag.composite.CompositeComponentBeanInfo) VariableMapper(jakarta.el.VariableMapper) UIComponent(jakarta.faces.component.UIComponent) UIPanel(jakarta.faces.component.UIPanel) VariableMapperWrapper(com.sun.faces.facelets.el.VariableMapperWrapper) FaceletContext(jakarta.faces.view.facelets.FaceletContext) IOException(java.io.IOException) FacesException(jakarta.faces.FacesException) FileNotFoundException(java.io.FileNotFoundException) FacesException(jakarta.faces.FacesException)

Aggregations

DefaultFaceletFactory (com.sun.faces.facelets.impl.DefaultFaceletFactory)2 VariableMapperWrapper (com.sun.faces.facelets.el.VariableMapperWrapper)1 DefaultResourceResolver (com.sun.faces.facelets.impl.DefaultResourceResolver)1 CompositeComponentBeanInfo (com.sun.faces.facelets.tag.composite.CompositeComponentBeanInfo)1 MessageUtils.getExceptionMessageString (com.sun.faces.util.MessageUtils.getExceptionMessageString)1 VariableMapper (jakarta.el.VariableMapper)1 FacesException (jakarta.faces.FacesException)1 UIComponent (jakarta.faces.component.UIComponent)1 UIPanel (jakarta.faces.component.UIPanel)1 Facelet (jakarta.faces.view.facelets.Facelet)1 FaceletCacheFactory (jakarta.faces.view.facelets.FaceletCacheFactory)1 FaceletContext (jakarta.faces.view.facelets.FaceletContext)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1