Search in sources :

Example 1 with XMLFrontMatterSaver

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

the class FaceletViewHandlingStrategy method buildView.

/**
 * @see ViewDeclarationLanguage#buildView(FacesContext, UIViewRoot)
 */
@Override
public void buildView(FacesContext ctx, UIViewRoot view) throws IOException {
    StateContext stateCtx = StateContext.getStateContext(ctx);
    if (isViewPopulated(ctx, view)) {
        Facelet facelet = faceletFactory.getFacelet(ctx, view.getViewId());
        // virute of re-applying the handlers.
        try {
            stateCtx.setTrackViewModifications(false);
            facelet.apply(ctx, view);
            reapplyDynamicActions(ctx);
            if (stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
                markInitialStateIfNotMarked(view);
            }
        } finally {
            stateCtx.setTrackViewModifications(true);
        }
        return;
    }
    view.setViewId(view.getViewId());
    LOGGER.log(FINE, () -> "Building View: " + view.getViewId());
    if (faceletFactory == null) {
        faceletFactory = ApplicationAssociate.getInstance(ctx.getExternalContext()).getFaceletFactory();
    }
    RequestStateManager.set(ctx, FACELET_FACTORY, faceletFactory);
    Facelet facelet = faceletFactory.getFacelet(ctx, view.getViewId());
    // populate UIViewRoot
    try {
        ctx.getAttributes().put(IS_BUILDING_INITIAL_STATE, Boolean.TRUE);
        stateCtx.setTrackViewModifications(false);
        facelet.apply(ctx, view);
        if (facelet instanceof XMLFrontMatterSaver) {
            XMLFrontMatterSaver frontMatterSaver = (XMLFrontMatterSaver) facelet;
            Doctype doctype = frontMatterSaver.getSavedDoctype();
            if (doctype != null) {
                saveDOCTYPEToFacesContextAttributes(doctype);
            }
            String XMLDECL = frontMatterSaver.getSavedXMLDecl();
            if (XMLDECL != null) {
                saveXMLDECLToFacesContextAttributes(XMLDECL);
            }
        }
        Doctype doctype = getDOCTYPEFromFacesContextAttributes(ctx);
        if (doctype != null) {
            view.setDoctype(doctype);
        }
        if (!stateCtx.isPartialStateSaving(ctx, view.getViewId())) {
            reapplyDynamicActions(ctx);
        }
        startTrackViewModifications(ctx, view);
    } finally {
        ctx.getAttributes().remove(IS_BUILDING_INITIAL_STATE);
    }
    ctx.getApplication().publishEvent(ctx, PostAddToViewEvent.class, UIViewRoot.class, view);
    markInitialState(ctx, view);
    setViewPopulated(ctx, view);
}
Also used : Facelet(jakarta.faces.view.facelets.Facelet) XMLFrontMatterSaver(com.sun.faces.facelets.impl.XMLFrontMatterSaver) StateContext.getStateContext(com.sun.faces.context.StateContext.getStateContext) StateContext(com.sun.faces.context.StateContext) Doctype(jakarta.faces.component.Doctype)

Aggregations

StateContext (com.sun.faces.context.StateContext)1 StateContext.getStateContext (com.sun.faces.context.StateContext.getStateContext)1 XMLFrontMatterSaver (com.sun.faces.facelets.impl.XMLFrontMatterSaver)1 Doctype (jakarta.faces.component.Doctype)1 Facelet (jakarta.faces.view.facelets.Facelet)1