Beispiel #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);
    }
  }
Beispiel #2
0
  public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
    // only process if it's been created
    if (null == parent
        || (null == (parent = parent.getParent()))
        || !(ComponentHandler.isNew(parent))) {
      return;
    }

    Map<String, Object> attrs = parent.getAttributes();

    CompositeComponentBeanInfo componentBeanInfo =
        (CompositeComponentBeanInfo) attrs.get(UIComponent.BEANINFO_KEY);
    assert (null != componentBeanInfo);
    List<PropertyDescriptor> declaredAttributes = componentBeanInfo.getPropertyDescriptorsList();

    // Get the value of required the name propertyDescriptor
    ValueExpression ve = name.getValueExpression(ctx, String.class);
    String strValue = (String) ve.getValue(ctx);

    // Search the propertyDescriptors for one for this attribute
    for (PropertyDescriptor cur : declaredAttributes) {
      if (strValue.endsWith(cur.getName())) {
        // If we have a match, no need to waste time
        // duplicating and replacing it.
        return;
      }
    }

    PropertyDescriptor propertyDescriptor;
    try {
      propertyDescriptor = new PropertyDescriptor(strValue, null, null);
      declaredAttributes.add(propertyDescriptor);
    } catch (IntrospectionException ex) {
      throw new TagException(
          tag, "Unable to create property descriptor for property " + strValue, ex);
    }

    for (TagAttribute tagAttribute : this.tag.getAttributes().getAll()) {
      String attributeName = tagAttribute.getLocalName();
      PropertyHandler handler = ATTRIBUTE_MANAGER.getHandler(ctx, attributeName);
      if (handler != null) {
        handler.apply(ctx, attributeName, propertyDescriptor, tagAttribute);
      }
    }

    this.nextHandler.apply(ctx, parent);
  }
  public void apply(FaceletContext ctx, UIComponent parent) throws IOException {

    // only process if it's been created
    if (parent == null || !ComponentHandler.isNew(parent)) {
      return;
    }

    if (isEventSource(parent)) {
      applyAttachedObject(ctx.getFacesContext(), parent);
    } else if (UIComponent.isCompositeComponent(parent)) {
      // Allow the composite component to know about the target component.
      TagHandlerUtils.getOrCreateRetargetableHandlersList(parent).add(this);
    } else {
      throw new TagException(
          this.tag, "Parent does not match event source requirements: " + parent);
    }
  }
Beispiel #4
0
  @Override
  public void applyNextHandler(FaceletContext ctx, UIComponent c)
      throws IOException, FacesException, ELException {

    // attributes need to be applied before any action is taken on
    // nested children handlers or the composite component handlers
    // as there may be an expression evaluated at tree creation time
    // that needs access to these attributes
    setAttributes(ctx, c);

    // Allow any nested elements that reside inside the markup element
    // for this tag to get applied
    super.applyNextHandler(ctx, c);

    // Apply the facelet for this composite component
    applyCompositeComponent(ctx, c);

    // Allow any PDL declared attached objects to be retargeted
    if (ComponentHandler.isNew(c)) {
      FacesContext context = ctx.getFacesContext();
      String viewId = context.getViewRoot().getViewId();
      // PENDING(rlubke): performance
      ViewDeclarationLanguageFactory factory =
          (ViewDeclarationLanguageFactory)
              FactoryFinder.getFactory(FactoryFinder.VIEW_DECLARATION_LANGUAGE_FACTORY);

      ViewDeclarationLanguage vdl = factory.getViewDeclarationLanguage(viewId);
      vdl.retargetAttachedObjects(context, c, getAttachedObjectHandlers(c, false));
      vdl.retargetMethodExpressions(context, c);

      // RELEASE_PENDING This is *ugly*.  See my comments in
      // ComponentTagHandlerDelegateImpl at the end of the apply()
      // method
      if (StateContext.getStateContext(context).partialStateSaving(context, viewId)) {
        markInitialState(c);
      }
    }
  }
  public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
    // only process if it's been created
    if (null == parent
        || (null == (parent = parent.getParent()))
        || !(ComponentHandler.isNew(parent))) {
      return;
    }

    Map<String, Object> attrs = parent.getAttributes();

    CompositeComponentBeanInfo componentBeanInfo =
        (CompositeComponentBeanInfo) attrs.get(UIComponent.BEANINFO_KEY);
    assert (null != componentBeanInfo);
    List<PropertyDescriptor> declaredAttributes = componentBeanInfo.getPropertyDescriptorsList();

    // Get the value of required the name propertyDescriptor
    ValueExpression ve = name.getValueExpression(ctx, String.class);
    String strValue = (String) ve.getValue(ctx);

    // Search the propertyDescriptors for one for this attribute
    for (PropertyDescriptor cur : declaredAttributes) {
      if (strValue.endsWith(cur.getName())) {
        // If we have a match, no need to waste time
        // duplicating and replacing it.
        return;
      }
    }

    PropertyDescriptor propertyDescriptor;
    try {
      propertyDescriptor = new CCAttributePropertyDescriptor(strValue, null, null);
      declaredAttributes.add(propertyDescriptor);
    } catch (IntrospectionException ex) {
      throw new TagException(
          tag, "Unable to create property descriptor for property " + strValue, ex);
    }

    TagAttribute defaultTagAttribute = null;
    PropertyHandler defaultHandler = null;
    for (TagAttribute tagAttribute : this.tag.getAttributes().getAll()) {
      String attributeName = tagAttribute.getLocalName();
      if ("default".equals(attributeName)) {
        // store the TagAttribute and the PropertyHandler for later
        // execution, as the handler for the default-attribute requires,
        // that the PropertyHandler for 'type' - if it exists - has been
        // applied first.
        defaultTagAttribute = tagAttribute;
        defaultHandler = ATTRIBUTE_MANAGER.getHandler(ctx, "default");
      } else {
        PropertyHandler handler = ATTRIBUTE_MANAGER.getHandler(ctx, attributeName);
        if (handler != null) {
          handler.apply(ctx, attributeName, propertyDescriptor, tagAttribute);
        }
      }
    }
    if (defaultHandler != null) {
      // If the 'default'-attribute of cc:attribute was set, apply the
      // previously stored PropertyHandler (see above) now, as now it is
      // guaranteed that if a 'type'-attribute existed, that its handler
      // was already applied
      try {
        defaultHandler.apply(ctx, "default", propertyDescriptor, defaultTagAttribute);
      } catch (IllegalArgumentException ex) {
        // If the type (according to the type-attribute) can not be
        // found, the DefaultPropertyHandler will wrapp the
        // ClassNotFoundException into an IllegalArgumentException,
        // which is unwrapped into a TagException here.
        throw new TagException(
            tag, "'type' could not be resolved: " + ex.getCause(), ex.getCause());
      }
    }

    this.nextHandler.apply(ctx, parent);
  }