示例#1
2
  protected void assignUniqueId(FaceletContext ctx, UIComponent parent, String id, UIComponent c) {

    // If the id is specified as a literal, and the component is being
    // repeated (by c:forEach, for example), use generated unique ids
    // after the first instance
    if (this.id != null && !(this.id.isLiteral() && ComponentSupport.getNeedUniqueIds(ctx))) {
      c.setId(this.id.getValue(ctx));
    } else {
      UIViewRoot root = ComponentSupport.getViewRoot(ctx, parent);
      if (root != null) {
        String uid;
        IdMapper mapper = IdMapper.getMapper(ctx.getFacesContext());
        String mid = ((mapper != null) ? mapper.getAliasedId(id) : id);
        UIComponent ancestorNamingContainer = parent.getNamingContainer();
        if (null != ancestorNamingContainer && ancestorNamingContainer instanceof UniqueIdVendor) {
          uid =
              ((UniqueIdVendor) ancestorNamingContainer).createUniqueId(ctx.getFacesContext(), mid);
        } else {
          uid = root.createUniqueId(ctx.getFacesContext(), mid);
        }
        c.setId(uid);
      }
    }

    if (this.rendererType != null) {
      c.setRendererType(this.rendererType);
    }
  }
示例#2
0
  public void apply(FaceletContext ctx, UIComponent parent)
      throws IOException, FacesException, FaceletException, ELException {

    Util.notNull("parent", parent);
    UIComponent facetComponent = parent.getFacets().get(UIViewRoot.METADATA_FACET_NAME);
    if (facetComponent == null) {
      parent.getAttributes().put(FacetHandler.KEY, UIViewRoot.METADATA_FACET_NAME);
      try {
        this.nextHandler.apply(ctx, parent);
      } finally {
        parent.getAttributes().remove(FacetHandler.KEY);
      }
      facetComponent = parent.getFacets().get(UIViewRoot.METADATA_FACET_NAME);
      if (!(facetComponent instanceof UIPanel)) {
        UIComponent panelGroup =
            ctx.getFacesContext().getApplication().createComponent(UIPanel.COMPONENT_TYPE);
        panelGroup.getAttributes().put(UIComponent.ADDED_BY_PDL_KEY, Boolean.TRUE);
        panelGroup.getChildren().add(facetComponent);
        parent.getFacets().put(UIViewRoot.METADATA_FACET_NAME, panelGroup);
        facetComponent = panelGroup;

        facetComponent.setId(UIViewRoot.METADATA_FACET_NAME);
      }
    }
  }
示例#3
0
    /**
     * Handle the add.
     *
     * @param context the Faces context.
     * @param component the UI component to add to the list as an ADD.
     */
    private void handleAdd(FacesContext context, UIComponent component) {
      if (!component.isTransient() && !hasTransientAncestor(component)) {
        if (component.getParent() != null && component.getParent().isInView()) {
          String id = component.getId();

          /*
           * Since adding a component, can mean you are really reparenting
           * it, we need to make sure the OLD clientId is not cached, we do
           * that by setting the id.
           */
          if (id != null) {
            component.setId(id);
          }

          if (component.getParent().getFacets().containsValue(component)) {
            Map facets = component.getParent().getFacets();
            Iterator entries = facets.entrySet().iterator();
            while (entries.hasNext()) {
              Map.Entry entry = (Map.Entry) entries.next();
              if (entry.getValue() == component) {
                incrementDynamicChildCount(component.getParent());
                component.clearInitialState();
                component
                    .getAttributes()
                    .put(DYNAMIC_COMPONENT, component.getParent().getChildren().indexOf(component));
                ComponentStruct struct = new ComponentStruct();
                struct.action = ComponentStruct.ADD;
                struct.facetName = entry.getKey().toString();
                struct.parentClientId = component.getParent().getClientId(context);
                struct.clientId = component.getClientId(context);
                struct.id = component.getId();
                handleAddRemoveWithAutoPrune(component, struct);
              }
            }
          } else {
            incrementDynamicChildCount(component.getParent());
            component.clearInitialState();
            component
                .getAttributes()
                .put(DYNAMIC_COMPONENT, component.getParent().getChildren().indexOf(component));
            ComponentStruct struct = new ComponentStruct();
            struct.action = ComponentStruct.ADD;
            struct.parentClientId = component.getParent().getClientId(context);
            struct.clientId = component.getClientId(context);
            struct.id = component.getId();
            handleAddRemoveWithAutoPrune(component, struct);
          }
        }
      }
    }
示例#4
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));
    }
  }
示例#5
0
 /**
  * Add a sub component to a UI component.
  *
  * <p>Since 6.0, does not the set the component as rendered anymore.
  *
  * @param context
  * @param parent
  * @param child
  * @param defaultChildId
  * @return child comp
  */
 public static UIComponent hookSubComponent(
     FacesContext context, UIComponent parent, UIComponent child, String defaultChildId) {
   // build a valid id using the parent id so that it's found everytime.
   String childId = child.getId();
   if (defaultChildId != null) {
     // override with default
     childId = defaultChildId;
   }
   // make sure it's set
   if (childId == null) {
     childId = context.getViewRoot().createUniqueId();
   }
   // reset client id
   child.setId(childId);
   child.setParent(parent);
   return child;
 }
示例#6
0
  @Override
  protected UIComponent createComponent(FacesContext context, String newId) throws JspException {
    Application app = context.getApplication();

    UIComponent component;

    if (_binding != null) {
      component = app.createComponent(_binding, context, getComponentType());
      component.setValueExpression("binding", _binding);
    } else component = app.createComponent(getComponentType());

    component.setId(getId());

    setProperties(component);

    return component;
  }
示例#7
0
  private void buildPanel(HtmlForm form, String panelId) {
    UIComponent panel, input0, input1, button0, button1, column0;
    HtmlDataTable data;
    HtmlOutputText output0;
    ArrayList<String> hobbits = new ArrayList<String>();
    hobbits.add("bilbo");
    hobbits.add("frodo");
    hobbits.add("merry");
    hobbits.add("pippin");
    hobbits.add("lumpy");
    ListDataModel dataModel = new ListDataModel(hobbits);

    panel = new UINamingContainer();
    panel.setId(panelId);
    form.getChildren().add(panel);

    input0 = new HtmlInputText();
    input0.setId("input0");
    panel.getChildren().add(input0);

    input1 = new HtmlInputText();
    input1.setId("input1");
    panel.getChildren().add(input1);

    data = new HtmlDataTable();
    data.setId("data");
    panel.getChildren().add(data);
    data.setValue(dataModel);
    data.setVar("hobbitName");
    String dataId = data.getClientId();

    column0 = new HtmlColumn();
    column0.setId("column0");
    data.getChildren().add(column0);

    output0 = new HtmlOutputText();
    output0.setId("output0");
    output0.setValue(
        getFacesContext()
            .getApplication()
            .getExpressionFactory()
            .createValueExpression(
                getFacesContext().getELContext(), "#{hobbitName}", String.class));
    column0.getChildren().add(output0);

    button0 = new HtmlCommandButton();
    button0.setId("button0");
    panel.getChildren().add(button0);

    button1 = new HtmlCommandButton();
    button1.setId("button1");
    panel.getChildren().add(button1);
  }
    public UIComponent buildWidget(
        String elementName, Map<String, String> attributes, UIMetawidget metawidget) {

      FacesContext context = FacesContext.getCurrentInstance();
      Application application = context.getApplication();
      Class<?> clazz = WidgetBuilderUtils.getActualClassOrType(attributes, null);

      if (clazz == null) {
        return null;
      }

      // Colors (as of RichFaces 3.3.1)

      if (Color.class.equals(clazz)) {
        if (WidgetBuilderUtils.isReadOnly(attributes)) {
          return FacesContext.getCurrentInstance()
              .getApplication()
              .createComponent(HtmlOutputText.COMPONENT_TYPE);
        }

        return application.createComponent("org.richfaces.ColorPicker");
      }

      // Suggestion box
      //
      // Note: for suggestion box to work in table column footer facets, you need
      // https://jira.jboss.org/jira/browse/RF-7700

      if (String.class.equals(clazz)) {
        String facesSuggest = attributes.get(FACES_SUGGEST);

        if (facesSuggest != null) {
          UIComponent stubComponent = application.createComponent(UIStub.COMPONENT_TYPE);
          List<UIComponent> children = stubComponent.getChildren();

          // Standard text box

          HtmlInputText inputText =
              (HtmlInputText) application.createComponent(HtmlInputText.COMPONENT_TYPE);
          inputText.setStyle(((HtmlMetawidget) metawidget).getStyle());
          inputText.setStyleClass(((HtmlMetawidget) metawidget).getStyleClass());
          children.add(inputText);

          UISuggestionBox suggestionBox =
              (UISuggestionBox) application.createComponent(HtmlSuggestionBox.COMPONENT_TYPE);

          // Lock the 'id's so they don't get changed. This is important for the
          // JavaScript getElementById that RichFaces generates. Also, do not just use
          // 'viewRoot.createUniqueId' because, as per the RenderKit specification:
          //
          // "If the value returned from component.getId() is non-null and does not start
          // with UIViewRoot.UNIQUE_ID_PREFIX, call component.getClientId() and render
          // the result as the value of the id attribute in the markup for the component."
          //
          // Therefore the 'id' attribute is never rendered, therefore the JavaScript
          // getElementById doesn't work. Add our own prefix instead

          inputText.setId("suggestionText_" + FacesUtils.createUniqueId());
          suggestionBox.setId("suggestionBox_" + FacesUtils.createUniqueId());

          // Suggestion box

          suggestionBox.setFor(inputText.getId());
          suggestionBox.setVar("_internal");
          children.add(suggestionBox);

          try {
            // RichFaces 3.2/JSF 1.2 mode
            //
            // Note: we wrap the MethodExpression as an Object[] to stop link-time
            // dependencies on javax.el.MethodExpression, so that we still work with
            // JSF 1.1
            //
            // Note: according to JavaDocs returnType is only important when literal
            // (i.e. without #{...}) expression is used, otherwise Object.class is fine
            // (http://community.jboss.org/message/516830#516830)

            Object[] methodExpression =
                new Object[] {
                  application
                      .getExpressionFactory()
                      .createMethodExpression(
                          context.getELContext(),
                          facesSuggest,
                          Object.class,
                          new Class[] {Object.class})
                };
            ClassUtils.setProperty(suggestionBox, "suggestionAction", methodExpression[0]);
          } catch (Exception e) {
            // RichFaces 3.1/JSF 1.1 mode

            MethodBinding methodBinding =
                application.createMethodBinding(facesSuggest, new Class[] {Object.class});
            suggestionBox.setSuggestionAction(methodBinding);
          }

          // Column
          //
          // Note: this must be javax.faces.component.html.HtmlColumn, not
          // org.richfaces.component.html.HtmlColumn. The latter displayed okay, but when
          // a value was selected it did not populate back to the HtmlInputText

          UIColumn column =
              (UIColumn)
                  application.createComponent(javax.faces.component.html.HtmlColumn.COMPONENT_TYPE);
          column.setId(FacesUtils.createUniqueId());
          suggestionBox.getChildren().add(column);

          // Output text box

          UIComponent columnText = application.createComponent(HtmlOutputText.COMPONENT_TYPE);
          columnText.setId(FacesUtils.createUniqueId());
          ValueBinding valueBinding = application.createValueBinding("#{_internal}");
          columnText.setValueBinding("value", valueBinding);
          column.getChildren().add(columnText);

          return stubComponent;
        }
      }

      return null;
    }