Ejemplo n.º 1
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);
    }
  }
Ejemplo n.º 2
0
 @Override
 public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
   String variable = this.var.getValue(ctx);
   ValueExpression obj = this.value.getValueExpression(ctx, Object.class);
   /*Object resolved = obj.getValue(ctx);
   ctx.getVariableMapper().setVariable(variable,
   		ctx.getExpressionFactory().createValueExpression(resolved, Object.class));*/
   ctx.getVariableMapper().setVariable(variable, obj);
 }
Ejemplo n.º 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;
  }
 @Override
 public void apply(FaceletContext ctx, UIComponent parent)
     throws IOException, FacesException, FaceletException, ELException {
   if (parent instanceof ActionSource) {
     // only process if parent was just created
     if (parent.getParent() == null) {
       ActionSource src = (ActionSource) parent;
       ActionListener listener =
           new MethodExpressionActionListener(
               new MetaMethodExpression(
                   value.getMethodExpression(ctx, null, ACTION_LISTENER_SIG),
                   ctx.getFunctionMapper(),
                   ctx.getVariableMapper()));
       src.addActionListener(listener);
     }
   } else {
     throw new TagException(tag, "Parent is not of type ActionSource, type is: " + parent);
   }
 }
Ejemplo n.º 5
0
 /*
  * (non-Javadoc)
  *
  * @see com.sun.facelets.FaceletHandler#apply(com.sun.facelets.FaceletContext,
  *      javax.faces.component.UIComponent)
  */
 public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
   String nameStr = this.name.getValue(ctx);
   ValueExpression valueVE = this.value.getValueExpression(ctx, Object.class);
   ctx.getVariableMapper().setVariable(nameStr, valueVE);
 }