コード例 #1
0
  /**
   * Build the view.
   *
   * @param ctx the {@link FacesContext} for the current request
   * @param view the {@link UIViewRoot} to populate based of the Facelet template
   * @throws IOException if an error occurs building the view.
   */
  @Override
  public void buildView(FacesContext ctx, UIViewRoot view) throws IOException {

    if (Util.isViewPopulated(ctx, view)) {
      return;
    }
    updateStateSavingType(ctx, view.getViewId());
    view.setViewId(view.getViewId());

    if (LOGGER.isLoggable(Level.FINE)) {
      LOGGER.fine("Building View: " + view.getViewId());
    }
    if (faceletFactory == null) {
      ApplicationAssociate associate = ApplicationAssociate.getInstance(ctx.getExternalContext());
      faceletFactory = associate.getFaceletFactory();
      assert (faceletFactory != null);
    }
    RequestStateManager.set(ctx, RequestStateManager.FACELET_FACTORY, faceletFactory);
    Facelet f = faceletFactory.getFacelet(view.getViewId());

    // populate UIViewRoot
    f.apply(ctx, view);
    doPostBuildActions(view);
    Util.setViewPopulated(ctx, view);
  }
コード例 #2
0
  private void applyCompositeComponent(FaceletContext ctx, UIComponent c) throws IOException {

    FacesContext facesContext = ctx.getFacesContext();
    FaceletFactory factory =
        (FaceletFactory) RequestStateManager.get(facesContext, RequestStateManager.FACELET_FACTORY);
    VariableMapper orig = ctx.getVariableMapper();

    UIPanel facetComponent;
    if (ComponentHandler.isNew(c)) {
      facetComponent = (UIPanel) facesContext.getApplication().createComponent("javax.faces.Panel");
      facetComponent.setRendererType("javax.faces.Group");
      c.getFacets().put(UIComponent.COMPOSITE_FACET_NAME, facetComponent);
    } else {
      facetComponent = (UIPanel) c.getFacets().get(UIComponent.COMPOSITE_FACET_NAME);
    }
    assert (null != facetComponent);

    try {
      Facelet f = factory.getFacelet(ccResource.getURL());

      VariableMapper wrapper =
          new VariableMapperWrapper(orig) {

            @Override
            public ValueExpression resolveVariable(String variable) {
              return super.resolveVariable(variable);
            }
          };
      ctx.setVariableMapper(wrapper);
      f.apply(facesContext, facetComponent);
    } finally {
      ctx.setVariableMapper(orig);
    }
  }
コード例 #3
0
  @Override
  public BeanInfo getComponentMetadata(FacesContext context, Resource ccResource) {
    // PENDING this implementation is terribly wasteful.
    // Must find a better way.
    CompositeComponentBeanInfo result;
    FaceletContext ctx =
        (FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY);
    FaceletFactory factory =
        (FaceletFactory) RequestStateManager.get(context, RequestStateManager.FACELET_FACTORY);
    VariableMapper orig = ctx.getVariableMapper();
    UIComponent tmp = context.getApplication().createComponent("javax.faces.NamingContainer");
    UIPanel facetComponent =
        (UIPanel) context.getApplication().createComponent("javax.faces.Panel");
    facetComponent.setRendererType("javax.faces.Group");
    tmp.getFacets().put(UIComponent.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(Resource.COMPONENT_RESOURCE_KEY, ccResource);

    Facelet f;

    try {
      f = factory.getFacelet(ccResource.getURL());
      VariableMapper wrapper =
          new VariableMapperWrapper(orig) {

            @Override
            public ValueExpression resolveVariable(String variable) {
              return super.resolveVariable(variable);
            }
          };
      ctx.setVariableMapper(wrapper);
      context.getAttributes().put(IS_BUILDING_METADATA, Boolean.TRUE);
      f.apply(context, facetComponent);
    } catch (Exception e) {
      if (e instanceof FacesException) {
        throw (FacesException) e;
      } else {
        throw new FacesException(e);
      }
    } finally {
      context.getAttributes().remove(IS_BUILDING_METADATA);
      ctx.setVariableMapper(orig);
    }
    result = (CompositeComponentBeanInfo) tmp.getAttributes().get(UIComponent.BEANINFO_KEY);

    return result;
  }