Esempio n. 1
0
 @Override
 public void apply(FaceletContext ctx, UIComponent parent)
     throws IOException, FacesException, FaceletException, ELException {
   FaceletHandlerHelper helper = new FaceletHandlerHelper(config);
   TagAttributes devAttrs =
       FaceletHandlerHelper.getTagAttributes(
           helper.createAttribute("id", FaceletHandlerHelper.generateDevContainerId(ctx, refId)),
           helper.createAttribute("styleClass", "displayN nxlDevContainer"),
           helper.createAttribute("layout", "block"));
   ComponentHandler dComp =
       helper.getHtmlComponentHandler(
           config.getTagId(), devAttrs, devHandler, PANEL_COMPONENT_TYPE, null);
   FaceletHandler nextHandler =
       new CompositeFaceletHandler(
           new FaceletHandler[] {
             helper.getDisableDevModeTagHandler(config.getTagId(), dComp), originalHandler
           });
   TagAttributes cAttrs =
       FaceletHandlerHelper.getTagAttributes(
           helper.createAttribute("id", FaceletHandlerHelper.generateDevRegionId(ctx, refId)),
           helper.createAttribute("styleClass", "nxlDevRegion"),
           helper.createAttribute("layout", "block"));
   ComponentHandler cComp =
       helper.getHtmlComponentHandler(
           config.getTagId(), cAttrs, nextHandler, PANEL_COMPONENT_TYPE, null);
   cComp.apply(ctx, parent);
 }
Esempio n. 2
0
 public ComponentTagHandlerDelegateImpl(ComponentHandler owner) {
   this.owner = owner;
   ComponentConfig config = owner.getComponentConfig();
   this.componentType = config.getComponentType();
   this.rendererType = config.getRendererType();
   this.id = owner.getTagAttribute("id");
   this.binding = owner.getTagAttribute("binding");
 }
Esempio n. 3
0
  @Override
  public MetaRuleset createMetaRuleset(Class type) {
    Util.notNull("type", type);
    MetaRuleset m = new MetaRulesetImpl(owner.getTag(), type);

    // ignore standard component attributes
    m.ignore("binding").ignore("id");

    // add auto wiring for attributes
    m.addRule(ComponentRule.Instance);

    // if it's an ActionSource
    if (ActionSource.class.isAssignableFrom(type)) {
      m.addRule(ActionSourceRule.Instance);
    }

    // if it's a ValueHolder
    if (ValueHolder.class.isAssignableFrom(type)) {
      m.addRule(ValueHolderRule.Instance);

      // if it's an EditableValueHolder
      if (EditableValueHolder.class.isAssignableFrom(type)) {
        m.ignore("submittedValue");
        m.ignore("valid");
        m.addRule(EditableValueHolderRule.Instance);
      }
    }

    // if it's a selectone or selectmany
    if (UISelectOne.class.isAssignableFrom(type) || UISelectMany.class.isAssignableFrom(type)) {
      m.addRule(RenderPropertyRule.Instance);
    }

    return m;
  }
Esempio n. 4
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);
    }
  }
Esempio n. 5
0
  protected void doNewComponentActions(FaceletContext ctx, String id, UIComponent c) {

    if (log.isLoggable(Level.FINE)) {
      log.fine(owner.getTag() + " Component[" + id + "] Created: " + c.getClass().getName());
    }
    // If this is NOT a composite component...
    if (null == createCompositeComponentDelegate) {
      // set the attributes and properties into the UIComponent instance.
      owner.setAttributes(ctx, c);
    }
    // otherwise, allow the composite component code to do it.

    // mark it owned by a facelet instance
    c.getAttributes().put(ComponentSupport.MARK_CREATED, id);

    if (ctx.getFacesContext().isProjectStage(ProjectStage.Development)) {
      // inject the location into the component
      c.getAttributes().put(UIComponent.VIEW_LOCATION_KEY, owner.getTag().getLocation());
    }
  }
Esempio n. 6
0
  /**
   * Specialized implementation to prevent caching of the MetaRuleset when ProjectStage is
   * Development.
   */
  @Override
  public void setAttributes(FaceletContext ctx, Object instance) {

    if (instance != null) {
      if (ctx.getFacesContext().isProjectStage(ProjectStage.Development)) {
        Metadata meta = createMetaRuleset(instance.getClass()).finish();
        meta.applyMetadata(ctx, instance);
      } else {
        super.setAttributes(ctx, instance);
      }
    }
  }
Esempio n. 7
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);
      }
    }
  }
Esempio n. 8
0
  protected void doExistingComponentActions(FaceletContext ctx, String id, UIComponent c) {

    // mark all children for cleaning
    if (log.isLoggable(Level.FINE)) {
      log.fine(owner.getTag() + " Component[" + id + "] Found, marking children for cleanup");
    }
    ComponentSupport.markForDeletion(c);
    /*
     * Repply the id, for the case when the component tree was changed, and the id's are set explicitly.
     */
    if (this.id != null) {
      c.setId(this.id.getValue(ctx));
    }
  }
Esempio n. 9
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);
    }
  }
Esempio n. 11
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 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);
  }
Esempio n. 12
0
  /**
   * Method handles UIComponent tree creation in accordance with the JSF 1.2 spec.
   *
   * <ol>
   *   <li>First determines this UIComponent's id by calling {@link
   *       javax.faces.view.facelets.ComponentHandler#getTagId()}.
   *   <li>Search the parent for an existing UIComponent of the id we just grabbed
   *   <li>If found, {@link
   *       com.sun.faces.facelets.tag.jsf.ComponentSupport#markForDeletion(javax.faces.component.UIComponent)
   *       mark} its children for deletion.
   *   <li>If <i>not</i> found, call {@link #createComponent(FaceletContext) createComponent}.
   *       <ol>
   *         <li>Only here do we apply {@link
   *             com.sun.faces.facelets.tag.MetaTagHandlerImpl#setAttributes(FaceletContext,
   *             Object)}
   *         <li>Set the UIComponent's id
   *         <li>Set the RendererType of this instance
   *       </ol>
   *   <li>Now apply the nextHandler, passing the UIComponent we've created/found.
   *   <li>Now add the UIComponent to the passed parent
   *   <li>Lastly, if the UIComponent already existed (found), then {@link
   *       ComponentSupport#finalizeForDeletion(UIComponent) finalize} for deletion.
   * </ol>
   *
   * @throws TagException if the UIComponent parent is null
   */
  @Override
  public void apply(FaceletContext ctx, UIComponent parent) throws IOException {
    FacesContext context = ctx.getFacesContext();

    // make sure our parent is not null
    if (parent == null) {
      throw new TagException(owner.getTag(), "Parent UIComponent was null");
    }

    // our id
    String id = ctx.generateUniqueId(owner.getTagId());

    // grab our component
    UIComponent c = findChild(ctx, parent, id);
    if (null == c
        && context.isPostback()
        && UIComponent.isCompositeComponent(parent)
        && parent.getAttributes().get(id) != null) {
      c = findReparentedComponent(ctx, parent, id);
    } else {
      /**
       * If we found a child that is dynamic, the actual parent might have changed, so we need to
       * remove it from the actual parent. The reapplyDynamicActions will then replay the actions
       * and will make sure it ends up in the correct order.
       */
      if (c != null
          && c.getParent() != parent
          && c.getAttributes().containsKey(DYNAMIC_COMPONENT)) {
        c.getParent().getChildren().remove(c);
      }
    }

    boolean componentFound = false;
    if (c != null) {
      componentFound = true;
      doExistingComponentActions(ctx, id, c);
    } else {
      c = this.createComponent(ctx);

      doNewComponentActions(ctx, id, c);
      assignUniqueId(ctx, parent, id, c);

      // hook method
      owner.onComponentCreated(ctx, c, parent);
    }

    CompositeComponentStackManager ccStackManager =
        CompositeComponentStackManager.getManager(context);
    boolean compcompPushed = pushComponentToEL(ctx, c, ccStackManager);

    if (ProjectStage.Development == context.getApplication().getProjectStage()) {
      ComponentSupport.setTagForComponent(context, c, this.owner.getTag());
    }

    // If this this a naming container, stop generating unique Ids
    // for the repeated tags
    boolean setUniqueIds = false;
    boolean oldUnique = false;
    if (c instanceof NamingContainer) {
      oldUnique = ComponentSupport.setNeedUniqueIds(ctx, false);
      setUniqueIds = true;
    }
    try {
      // first allow c to get populated
      owner.applyNextHandler(ctx, c);
    } finally {
      if (setUniqueIds) ComponentSupport.setNeedUniqueIds(ctx, oldUnique);
    }

    // finish cleaning up orphaned children
    if (componentFound) {
      doOrphanedChildCleanup(ctx, parent, c);
    }

    this.privateOnComponentPopulated(ctx, c);
    owner.onComponentPopulated(ctx, c, parent);
    // add to the tree afterwards
    // this allows children to determine if it's
    // been part of the tree or not yet
    addComponentToView(ctx, parent, c, componentFound);
    adjustIndexOfDynamicChildren(context, c);
    popComponentFromEL(ctx, c, ccStackManager, compcompPushed);
  }
 @Override
 public void apply(FaceletContext ctx, UIComponent parent, Widget widget)
     throws WidgetException, IOException {
   FaceletHandlerHelper helper = new FaceletHandlerHelper(tagConfig);
   String mode = widget.getMode();
   String widgetId = widget.getId();
   String widgetName = widget.getName();
   String widgetTagConfigId = widget.getTagConfigId();
   TagAttributes attributes;
   if (BuiltinWidgetModes.isLikePlainMode(mode)) {
     // use attributes without id
     attributes = helper.getTagAttributes(widget);
   } else {
     if (BuiltinWidgetModes.EDIT.equals(mode)) {
       // exclude styleClass, it needs a specific css class also, see
       // below
       attributes = helper.getTagAttributes(widget, Arrays.asList("styleClass"), true);
       attributes =
           FaceletHandlerHelper.addTagAttribute(
               attributes, helper.createAttribute("id", widgetId));
     } else {
       attributes = helper.getTagAttributes(widgetId, widget);
     }
   }
   FaceletHandler leaf = getNextHandler(ctx, tagConfig, widget, null, helper);
   if (BuiltinWidgetModes.EDIT.equals(mode)) {
     ComponentHandler input =
         helper.getHtmlComponentHandler(
             widgetTagConfigId, attributes, leaf, UIHtmlEditor.COMPONENT_TYPE, null);
     String msgId = FaceletHandlerHelper.generateMessageId(ctx, widgetName);
     ComponentHandler message =
         helper.getMessageComponentHandler(widgetTagConfigId, msgId, widgetId, null);
     FaceletHandler[] handlers = {input, message};
     FaceletHandler h = new CompositeFaceletHandler(handlers);
     h.apply(ctx, parent);
   } else {
     // default on text for other modes, do not escape
     TagAttribute escape = helper.createAttribute("escape", "false");
     attributes = FaceletHandlerHelper.addTagAttribute(attributes, escape);
     String styleClass = (String) widget.getProperty("styleClass");
     TagAttribute styleClassAttr =
         helper.createAttribute(
             "styleClass",
             StringUtils.isBlank(styleClass) ? "textBlock" : "textBlock " + styleClass);
     attributes = FaceletHandlerHelper.addTagAttribute(attributes, styleClassAttr);
     ComponentHandler output =
         helper.getHtmlComponentHandler(
             widgetTagConfigId, attributes, leaf, HtmlOutputText.COMPONENT_TYPE, null);
     if (BuiltinWidgetModes.PDF.equals(mode)) {
       // add a surrounding p:html tag handler
       FaceletHandler h =
           helper.getHtmlComponentHandler(
               widgetTagConfigId,
               new TagAttributesImpl(new TagAttribute[0]),
               output,
               UIHtmlText.class.getName(),
               null);
       h.apply(ctx, parent);
     } else {
       output.apply(ctx, parent);
     }
   }
 }