Search in sources :

Example 1 with FacesFileNotFoundException

use of com.sun.faces.context.FacesFileNotFoundException in project mojarra by eclipse-ee4j.

the class ViewMetadataImpl method createMetadataView.

/**
 * @see jakarta.faces.view.ViewMetadata#createMetadataView(jakarta.faces.context.FacesContext)
 */
@Override
public UIViewRoot createMetadataView(FacesContext context) {
    UIViewRoot metadataView = null;
    UIViewRoot currentViewRoot = context.getViewRoot();
    Map<String, Object> currentViewMapShallowCopy = emptyMap();
    try {
        context.setProcessingEvents(false);
        if (faceletFactory == null) {
            faceletFactory = ApplicationAssociate.getInstance(context.getExternalContext()).getFaceletFactory();
        }
        metadataView = context.getApplication().getViewHandler().createView(context, viewId);
        // Stash away view id before invoking handlers so that
        // StateContext.partialStateSaving() can determine the current
        // view.
        context.getAttributes().put(RIConstants.VIEWID_KEY_NAME, viewId);
        // copied to the temporary UIViewRoot before invoking handlers.
        if (currentViewRoot != null) {
            Map<String, Object> currentViewMap = currentViewRoot.getViewMap(false);
            if (!isEmpty(currentViewMap)) {
                metadataView.getViewMap(true).putAll(new HashMap<>(currentViewMap));
            }
        }
        // Only replace the current context's UIViewRoot if there is one to replace.
        if (currentViewRoot != null) {
            // This clears the ViewMap of the current UIViewRoot before
            // setting the argument as the new UIViewRoot.
            context.setViewRoot(metadataView);
        }
        faceletFactory.getMetadataFacelet(context, metadataView.getViewId()).applyMetadata(context, metadataView);
        importConstantsIfNecessary(context, metadataView);
    } catch (FacesFileNotFoundException ffnfe) {
        try {
            context.getExternalContext().responseSendError(404, ffnfe.getMessage());
        } catch (IOException ioe) {
        }
        context.responseComplete();
    } catch (IOException ioe) {
        throw new FacesException(ioe);
    } finally {
        context.getAttributes().remove(VIEWID_KEY_NAME);
        if (currentViewRoot != null) {
            context.setViewRoot(currentViewRoot);
            if (!currentViewMapShallowCopy.isEmpty()) {
                currentViewRoot.getViewMap(true).putAll(currentViewMapShallowCopy);
                currentViewMapShallowCopy.clear();
            }
        }
        context.setProcessingEvents(true);
    }
    return metadataView;
}
Also used : FacesFileNotFoundException(com.sun.faces.context.FacesFileNotFoundException) IOException(java.io.IOException) UIViewRoot(jakarta.faces.component.UIViewRoot) FacesException(jakarta.faces.FacesException)

Aggregations

FacesFileNotFoundException (com.sun.faces.context.FacesFileNotFoundException)1 FacesException (jakarta.faces.FacesException)1 UIViewRoot (jakarta.faces.component.UIViewRoot)1 IOException (java.io.IOException)1