TBH I don't see this as a very common usecase. And it's not difficult
to implement on your own (although the code isn't entirely trivial).

-Matej

On 6/5/07, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> That looks like a lot of work actually. Johan, others, you think we
> should build in better support for this in Wicket?
>
> Eelco
>
> On 6/5/07, dukejansen <[EMAIL PROTECTED]> wrote:
> >  I've gone ahead and implemented this, but instead of using the
> > Component.saveInnermostModel method, I coded up my own. The implementation
> > in Component only traverses IWrapModel implementations, not IChainedModel
> > implementations. My implementation handles both. Note that this will only
> > find components backed by the exact same IModel instance. Two distinct model
> > objects wrapping the exact same object will not match. /**
> >  * Searches the component tree and finds any components backed by the same
> > model as the model passed in, then
> >  * adds those components to the given AjaxRequestTarget to be rendered
> > (after first verifying that they have
> >  * outputMarkupId set to true).
> >  *
> >  * @param root the root MarkupContainer whose descendents will be examined
> > for matching backing models
> >  * @param target the AjaxRequestTarget to add all the matching components to
> >  * @param model the model to match
> >  */
> >  public static void
> > addComponentsBackedBySameModel(MarkupContainer root, final
> > AjaxRequestTarget target, final IModel model) {
> >
> >  // Visit all children, looking for components backed by the same model.
> >  root.visitChildren(new IVisitor() {
> >  public Object component(Component component) {
> >  if (WicketUtils.isSameInnermostModel(component.getModel(),
> > model)) {
> >  if (component.getOutputMarkupId()) {
> >  // Refresh the component.
> >  target.addComponent(component);
> >  // No need to go deeper if we're already refreshing the entire component!
> >  return IVisitor.CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
> >  }
> >  }
> >  return IVisitor.CONTINUE_TRAVERSAL;
> >  }
> >  });
> >
> >  // TODO: Return the list of components that were re-rendered?
> >  // See also:
> >  //
> > http://www.nabble.com/Best-Practices-for-accessing-repainting-sibling-cousin-components--tf3841514.html
> >
> >  }
> >
> >  /**
> >  * Returns true if the given models ultimately share the same innermost
> > model;
> >  * otherwise returns false.
> >  *
> >  * @param model1 the first model
> >  * @param model2 the second model
> >  * @return true if they share the same innermost model; otherwise
> >  * false
> >  */
> >  public static boolean isSameInnermostModel(IModel model1, IModel model2) {
> >  // There is a version of this on Component, but it is only aware of
> > IWrapModel.
> >  // Our version knows how to traverse chained models as well as warpped
> > models.
> >  if (model1 != null && model2 != null) {
> >  return getInnermostModel(model1) == getInnermostModel(model2);
> >  } else {
> >  return false;
> >  }
> >  }
> >
> >  /**
> >  * Returns the innermost model within the given model; similar to
> > Component.getInnermostModel,
> >  * except that it follows both IWrapModel and IChainingModel, not just the
> > former.
> >  *
> >  * @param model the model
> >  * @return the innermost model within that model
> >  */
> >  public static IModel getInnermostModel(IModel model) {
> >
> >  // Pass through nulls.
> >  if (model == null) {
> >  return null;
> >  }
> >
> >  // Try to figure out an inner model.
> >  IModel innerModel = null;
> >  if (model instanceof IWrapModel) {
> >  innerModel =
> > getInnermostModel(((IWrapModel)model).getWrappedModel());
> >  } else if (model instanceof IChainingModel) {
> >  innerModel =
> > getInnermostModel(((IChainingModel)model).getChainedModel());
> >  }
> >
> >  if (innerModel != null) {
> >  // If we got an inner model, return it.
> >  return innerModel;
> >  } else {
> >  // Otherwise the given model was the innermost, so return it.
> >  return model;
> >  }
> >
> >  }
> >
> >  /**
> >  * Returns the root ancestor of this component by walking up the parent tree
> > until a component is found with no parent;
> >  * note that this could return the same component passed in.
> >  *
> >  * @param component the component whose root ancestor should be returned;
> > must be non-null
> >  * @return the root ancestor
> >  */
> >  public static Component getRootAncestor(Component component) {
> >  ExceptionUtils.throwIfNull(component, "component");
> >  Component cur = component;
> >  while (cur.getParent() != null) {
> >  cur = cur.getParent();
> >  }
> >  return cur;
> >  }
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by DB2 Express
> Download DB2 Express C - the FREE version of DB2 express and take
> control of your XML. No limits. Just data. Click to get it now.
> http://sourceforge.net/powerbar/db2/
> _______________________________________________
> Wicket-user mailing list
> Wicket-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to