List of usage examples for org.apache.wicket MarkupContainer getMetaData
public final <M extends Serializable> M getMetaData(final MetaDataKey<M> key)
From source file:org.wicketstuff.minis.component.ListViewFormComponentReuseManager.java
License:Apache License
/** * Either adds the given <code>newComponent</code> to the parent or reuses an existing component * instance previously used with the same model object. * /*from w ww . j ava 2s . com*/ * @param <T> * @param parent * @param newComponent * @return <code>newComponent</code> or a component previously bound to the same model object */ public static <T extends FormComponent<?>> T addOrReuse(final MarkupContainer parent, final T newComponent) { Object rowModelObject = null; MarkupContainer current = parent; while (current != null) { if (current instanceof ListItem<?>) rowModelObject = current.getDefaultModelObject(); if (current instanceof ListView) { ListViewFormComponentReuseManager mgr = current.getMetaData(REUSE_MANAGER_META_KEY); if (mgr == null) { mgr = new ListViewFormComponentReuseManager(); current.setMetaData(REUSE_MANAGER_META_KEY, mgr); } @SuppressWarnings("unchecked") final T componentToUse = (T) mgr.rememberOrReuse(rowModelObject, (FormComponent<?>) newComponent); parent.add(componentToUse); return componentToUse; } current = current.getParent(); } return newComponent; }