/** * Builds the view if not already available. This is mostly required for ViewExpiredException's. * * @param context The {@link FacesContext}. * @param throwable The occurred {@link Throwable}. * @param rootCause The root cause. * @return The unwrapped {@link Throwable}. * @throws java.io.IOException If building the view fails. */ protected Throwable buildView(FacesContext context, Throwable throwable, Throwable rootCause) throws IOException { if (context.getViewRoot() == null) { ViewHandler viewHandler = context.getApplication().getViewHandler(); String viewId = viewHandler.deriveViewId(context, ComponentUtils.calculateViewId(context)); ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(context, viewId); UIViewRoot viewRoot = vdl.createView(context, viewId); context.setViewRoot(viewRoot); vdl.buildView(context, viewRoot); // Workaround for Mojarra // if UIViewRoot == null -> 'IllegalArgumentException' is throwed instead of 'ViewExpiredException' if (rootCause == null && throwable instanceof IllegalArgumentException) { rootCause = new javax.faces.application.ViewExpiredException(viewId); } } return rootCause; }
@Override public void renderView(FacesContext context, UIViewRoot view) throws IOException { delegate.renderView(context, view); }
@Override public StateManagementStrategy getStateManagementStrategy(FacesContext context, String viewId) { return delegate.getStateManagementStrategy(context, viewId); }
UIViewRoot view = context.getViewRoot(); Application application = context.getApplication(); ViewDeclarationLanguage vdl = application.getViewHandler().getViewDeclarationLanguage(context, view.getViewId()); BeanInfo metadata = vdl.getComponentMetadata(context, componentResource); if (metadata == null) if (componentType != null) component = application.createComponent((String) componentType.getValue(context.getELContext())); annotationsApplied = true; resource = vdl.getScriptComponentResource(context, componentResource); if (resource != null) component = application.createComponent(context, UINamingContainer.COMPONENT_TYPE, null); annotationsApplied = true; component.setRendererType("javax.faces.Composite"); component.getAttributes().put(Resource.COMPONENT_RESOURCE_KEY, componentResource); component.getAttributes().put(UIComponent.BEANINFO_KEY, metadata);
protected void applyFinalInitializationSteps(FaceletContext ctx, FaceletCompositionContext mctx, UIComponent c) { FacesContext facesContext = ctx.getFacesContext(); ViewDeclarationLanguage vdl = facesContext.getApplication().getViewHandler(). getViewDeclarationLanguage(facesContext, facesContext.getViewRoot().getViewId()); List<AttachedObjectHandler> handlers = mctx.getAttachedObjectHandlers(c); if (handlers != null) { vdl.retargetAttachedObjects(facesContext, c, handlers); // remove the list of handlers, as it is no longer necessary mctx.removeAttachedObjectHandlers(c); } vdl.retargetMethodExpressions(facesContext, c); if ( FaceletCompositionContext.getCurrentInstance(ctx).isMarkInitialState()) { // Call it only if we are using partial state saving c.markInitialState(); // Call it to other components created not bound by a tag handler c.getFacet(UIComponent.COMPOSITE_FACET_NAME).markInitialState(); } }
private void encodeViewParameters(FacesContext context) { ViewDeclarationLanguage vdl = context.getApplication().getViewHandler(). getViewDeclarationLanguage(context, getViewId()); if (vdl == null) { return; } ViewMetadata metadata = vdl.getViewMetadata(context, getViewId()); if (metadata != null) { // perhaps it's not supported Collection<UIViewParameter> params = ViewMetadata.getViewParameters(this); if (params.isEmpty()) { return; } try { for (UIViewParameter param : params) { param.encodeAll(context); } } catch (IOException e) { // IOException is forced by contract and is not expected to be thrown in this case throw new RuntimeException("Unexpected IOException", e); } } }
private void renderErrorPage(final FacesContext facesContext, final String errorPageLocation) throws IOException { final ViewHandler viewHandler = facesContext.getApplication().getViewHandler(); final UIViewRoot viewRoot = viewHandler.createView(facesContext, errorPageLocation); facesContext.setViewRoot(viewRoot); facesContext.getPartialViewContext().setRenderAll(true); final ViewDeclarationLanguage viewDeclarationLanguage = viewHandler .getViewDeclarationLanguage(facesContext, errorPageLocation); viewDeclarationLanguage.buildView(facesContext, viewRoot); facesContext.getApplication().publishEvent(facesContext, PreRenderViewEvent.class, viewRoot); viewDeclarationLanguage.renderView(facesContext, viewRoot); facesContext.responseComplete(); }
/** * Updates the component state stored in View scope so that it remains in sync with the updated flow execution * snapshot */ public void saveState() { FacesContext facesContext = FlowFacesContext.getCurrentInstance(); facesContext.setViewRoot(this.viewRoot); ViewDeclarationLanguage viewDeclarationLanguage = facesContext.getApplication().getViewHandler() .getViewDeclarationLanguage(facesContext, this.viewId); StateManagementStrategy stateManagementStrategy = (viewDeclarationLanguage == null ? null : viewDeclarationLanguage.getStateManagementStrategy(facesContext, this.viewId)); if (stateManagementStrategy != null) { stateManagementStrategy.saveView(facesContext); } }
/** * @see Faces#getMetadataAttributes(String) */ public static Map<String, Object> getMetadataAttributes(FacesContext context, String viewId) { ViewHandler viewHandler = context.getApplication().getViewHandler(); ViewDeclarationLanguage vdl = viewHandler.getViewDeclarationLanguage(context, viewId); ViewMetadata metadata = vdl.getViewMetadata(context, viewId); return (metadata != null) ? metadata.createMetadataView(context).getAttributes() : Collections.<String, Object>emptyMap(); }
@Override public void renderView(FacesContext context, UIViewRoot viewToRender) throws IOException, FacesException { checkNull(context, "context"); checkNull(viewToRender, "viewToRender"); // we cannot use this.getVDL() directly (see getViewHandler()) //String viewId = viewToRender.getViewId(); //getViewHandler(context).getViewDeclarationLanguage(context, viewId) // .renderView(context, viewToRender); // -= Leonardo Uribe =- Temporally reverted by TCK issues. getViewDeclarationLanguage(context,viewToRender.getViewId()).renderView(context, viewToRender); }
String viewId = "/path/to/some.xhtml"; FacesContext context = FacesContext.getCurrentInstance(); ViewDeclarationLanguage vdl = context.getApplication().getViewHandler().getViewDeclarationLanguage(context, viewId); UIViewRoot view = vdl.createView(context, viewId); vdl.buildView(context, view); // view should now have children.
@Override public ViewMetadata getViewMetadata(FacesContext context, String viewId) { return getWrapped().getViewMetadata(context, viewId); }
@Override public void buildView(FacesContext context, UIViewRoot root) throws IOException { getWrapped().buildView(context, root); }
@Override public BeanInfo getComponentMetadata(FacesContext context, Resource componentResource) { return delegate.getComponentMetadata(context, componentResource); }
@Override public Resource getScriptComponentResource(FacesContext context, Resource componentResource) { return delegate.getScriptComponentResource(context, componentResource); }
@Override public UIViewRoot createView(FacesContext context, String viewId) { return getWrapped().createView(context, viewId); }
public UIViewRoot restoreView(FacesContext context, String viewId) { return getWrapped().restoreView(context, viewId); }
@Override public void retargetAttachedObjects(FacesContext context, UIComponent topLevelComponent, List<AttachedObjectHandler> handlers) { delegate.retargetAttachedObjects(context, topLevelComponent, handlers); }
@Override public void retargetMethodExpressions(FacesContext context, UIComponent topLevelComponent) { delegate.retargetMethodExpressions(context, topLevelComponent); }
UIViewRoot view = context.getViewRoot(); Application application = context.getApplication(); ViewDeclarationLanguage vdl = application.getViewHandler().getViewDeclarationLanguage( context, view.getViewId()); BeanInfo metadata = vdl.getComponentMetadata(context, componentResource); if (metadata == null) if (componentType != null) component = application.createComponent((String) componentType.getValue(context.getELContext())); annotationsApplied = true; resource = vdl.getScriptComponentResource(context, componentResource); if (resource != null) component = application.createComponent(UINamingContainer.COMPONENT_TYPE); annotationsApplied = true; component.setRendererType("javax.faces.Composite"); component.getAttributes().put(Resource.COMPONENT_RESOURCE_KEY, componentResource); component.getAttributes().put(UIComponent.BEANINFO_KEY, metadata);