/** * Replaces this component with another. The replacing component must have the same component id * as this component. This method serves as a shortcut to * <code>this.getParent().replace(replacement)</code> and provides a better context for * errors. * * @since 1.2.1 * * @param replacement * component to replace this one */ public void replaceWith(Component replacement) { if (replacement == null) { throw new IllegalArgumentException("Argument [[replacement]] cannot be null."); } if (!getId().equals(replacement.getId())) { throw new IllegalArgumentException( "Replacement component must have the same id as the component it will replace. Replacement id [[" + replacement.getId() + "]], replaced id [[" + getId() + "]]."); } if (parent == null) { throw new IllegalStateException( "This method can only be called on a component that has already been added to its parent."); } parent.replace(replacement); }
"This method can only be called on a component that has already been added to its parent."); parent.replace(replacement);
"This method can only be called on a component that has already been added to its parent."); parent.replace(replacement); return replacement;
"This method can only be called on a component that has already been added to its parent."); parent.replace(replacement); return replacement;
/** * Replaces a child component of this container with another or just adds it in case no child * with the same id existed yet. * * @param child * The child * @return This */ public final MarkupContainer addOrReplace(final Component child) { checkHierarchyChange(child); if (child == null) { throw new IllegalArgumentException("argument child must be not null"); } if (get(child.getId()) == null) { add(child); } else { replace(child); } return this; }
/** * Replaces a child component of this container with another or just adds it in case no child * with the same id existed yet. * * @param childs * The child(s) to be added or replaced * @return This */ public final MarkupContainer addOrReplace(final Component... childs) { for (Component child : childs) { if (child == null) { throw new IllegalArgumentException("argument child must be not null"); } checkHierarchyChange(child); if (get(child.getId()) == null) { add(child); } else { replace(child); } } return this; }
/** * Performs the replacement, only if an actual replacement was constructed. * * @see org.apache.wicket.markup.html.link.Link#onClick() * @see #getReplacementFor(Component, String, Class) * @throws WicketRuntimeException * if a problem occurs in replacing the container. */ @Override public final void onClick() { Component replaceMe = getComponentToBeReplaced(); if (replaceMe == null) throw new WicketRuntimeException("unable to find child with id: " + containerId + " on parent: " + containerParent); Class<? extends MarkupContainer> myReplacementClass = getReplacementClass(); MarkupContainer replacement = getReplacementFor(replaceMe, containerId, myReplacementClass); if (replacement == null) return; // do nothing if (!containerId.equals(replacement.getId())) throw new WicketRuntimeException("The replacement does not have the specified id: " + containerId + ", but id: " + replacement.getId()); if (myReplacementClass.isAssignableFrom(replacement.getClass())) containerParent.replace(replacement); else throw new WicketRuntimeException("The replacement for " + containerId + " on " + containerParent + " is not assignable from " + myReplacementClass); }
/** * Performs the replacement, only if an actual replacement was constructed. * * @see org.apache.wicket.markup.html.link.Link#onClick() * @see #getReplacementFor(Component, String, Class) * @throws WicketRuntimeException * if a problem occurs in replacing the container. */ @Override public final void onClick() { Component replaceMe = getComponentToBeReplaced(); if (replaceMe == null) throw new WicketRuntimeException("unable to find child with id: " + containerId + " on parent: " + containerParent); Class<? extends MarkupContainer> myReplacementClass = getReplacementClass(); MarkupContainer replacement = getReplacementFor(replaceMe, containerId, myReplacementClass); if (replacement == null) return; // do nothing if (!containerId.equals(replacement.getId())) throw new WicketRuntimeException("The replacement does not have the specified id: " + containerId + ", but id: " + replacement.getId()); if (myReplacementClass.isAssignableFrom(replacement.getClass())) containerParent.replace(replacement); else throw new WicketRuntimeException("The replacement for " + containerId + " on " + containerParent + " is not assignable from " + myReplacementClass); }
/** * Replaces a child component of this container with another or just adds it in case no child * with the same id existed yet. * * @param children * The child(ren) to be added or replaced * @return this markup container */ public MarkupContainer addOrReplace(final Component... children) { for (Component child : children) { Args.notNull(child, "child"); checkHierarchyChange(child); if (get(child.getId()) == null) { add(child); } else { replace(child); } } return this; }
/** * Replaces a child component of this container with another or just adds it in case no child * with the same id existed yet. * * @param children * The child(ren) to be added or replaced * @return this markup container */ public MarkupContainer addOrReplace(final Component... children) { for (Component child : children) { Args.notNull(child, "child"); checkHierarchyChange(child); if (get(child.getId()) == null) { add(child); } else { replace(child); } } return this; }
container.replace(stub); // ok here because we are replacing auto with auto