Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Tree and table debugId problem
Hi all,
i have the following problem:
I want to add a unique id to the rendered items of a Tree component or Table, but i fail to do so. The setDebugId method only exists for Components, but if i have for example a search result table, i want to add ids to the rows so i can safely select one row.
Did i miss something?
A little bit code from our Tree component:
What i want is, when i add a new node in the Tree, i also want to add an id to it.
Any help? Do i something wrong? Is it possible at all?
public final class ExplorerTreeComponent extends Tree implements Action.Handler
{
private static final long serialVersionUID = 1L;
private final TypeContainer dataSource;
ExplorerTreeComponent(final TypeContainer typeContainer)
{
dataSource = typeContainer;
setContainerDataSource( dataSource );
setSelectable( true );
setImmediate( true );
setNullSelectionAllowed( false );
addActionHandler( this );
}
@Override
public Action[] getActions( Object target, Object sender )
{
if( target != null )
{
return dataSource.getItem( target ).getActions();
}
else
{
return new Action[0];
}
}
@Override
public void handleAction( Action action, Object sender, Object target )
{
// note: we do not select the node for which the action is executed since the query does not change
// http://dev.vaadin.com/ticket/6153, see http://dev.vaadin.com/ticket/7327
dataSource.getItem( target ).handleAction( action );
}
/** for use in unit tests **/
public TypeContainer getDataSource()
{
return dataSource;
}
}
public final class TypeContainer extends HierarchicalContainer
{
private static final long serialVersionUID = 1L;
private final HashMap<WrappedType, ExplorerBean> explorerBeans = new HashMap<WrappedType, ExplorerBean>();
public TypeContainer()
{
for( WrappedType wrappedType : TypeRegistry.getInstance().getWrappedTypesSortedByHierarchy() )
{
if( wrappedType.isBound() )
{
final ExplorerBean node = getOrCreateExplorerTreeNode( wrappedType );
if( wrappedType.getWrappedSuperType() != null )
{
final ExplorerBean superBean = explorerBeans.get( wrappedType.getWrappedSuperType() );
setChildrenAllowed( superBean, true );
setParent( node, superBean );
}
else
{
for( WrappedType container : TypeRegistry.getInstance().getPartOfContainers( wrappedType ) )
{
// in some cases the container has no ExplorerBean when we process a partOf, so we have to create one.
// example: when the ScalePrice WrappedType-node will be created a Variant ExplorerBean does not exist because it is later
// in the getWrappedTypesSortedByHierarchy()-List
final ExplorerBean containerBean = getOrCreateExplorerTreeNode( container );
if( getParent( node ) == null )
{
setChildrenAllowed( containerBean, true );
setParent( node, containerBean );
}
else
{
// we have to create a new node if we want to see scalePrice on all occurrences in the model
// TODO add newNode to explorerBeans- Map, if PartOfs have to be with all parent-nodes
// final ExplorerBean newNode = createExplorerTreeNode( wrappedType );
// setChildrenAllowed( containerBean, true );
// setParent( newNode, containerBean );
}
}
}
}
}
}
private ExplorerBean getOrCreateExplorerTreeNode( WrappedType wrappedType )
{
final ExplorerBean node;
// Because we create ExplorerBeans when we need them for PartOfs, we have to check that we don't create duplicates
if( explorerBeans.get( wrappedType ) == null )
{
node = createExplorerTreeNode( wrappedType );
}
else
{
node = explorerBeans.get( wrappedType );
}
return node;
}
private ExplorerBean createExplorerTreeNode( WrappedType wrappedType )
{
final ExplorerBean node = createExplorerBean( wrappedType );
addItem( node );
setChildrenAllowed( node, false );
return node;
}
@Override
public Item addItem(Object itemId)
{
if (!(itemId instanceof ExplorerBean))
throw new RuntimeException();
final ExplorerBean bean = (ExplorerBean)itemId;
// TODO if partOfs have to be displayed with all parents, we need to change the Map
explorerBeans.put( bean.getWrappedType(), bean );
return super.addItem(itemId);
}
@Override
public ExplorerBean getItem(Object itemId)
{
return (ExplorerBean)itemId;
}
private ExplorerBean createExplorerBean( WrappedType wrappedType )
{
if( wrappedType instanceof WrappedSingletonType )
{
return new SingletonExplorerBean( (WrappedSingletonType)wrappedType );
}
else
{
return new ExplorerBean( wrappedType );
}
}
};
public class ExplorerBean extends PropertysetItem
{
protected final WrappedType wrappedType;
private static final long serialVersionUID = 1L;
private Action createAction;
public ExplorerBean( final WrappedType wrappedType )
{
super();
this.wrappedType = wrappedType;
addItemProperty("id", new ObjectProperty<String>(getTreeId(), String.class));
}
public final String getTreeId()
{
return wrappedType.getName();
}
public WrappedType getWrappedType()
{
return wrappedType;
}
public Action[] getActions()
{
if ( getCreateAction() == null )
{
return new Action[0];
}
else
{
return new Action[]{getCreateAction()};
}
}
protected Action getCreateAction()
{
if( createAction == null && !wrappedType.isAbstract() )
{
createAction = new Action("Create new "+getTreeId());
}
return createAction;
}
public void handleAction(Action action)
{
if (action.equals(getCreateAction()) )
{
final EditorBean bean = new EditorBean(wrappedType);
VaadinApp.getInstance().getDefaultContentWindow().openItemCreator(bean);
}
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof ExplorerBean))
return false;
return super.equals(obj) && wrappedType.equals(((ExplorerBean)obj).wrappedType);
}
@Override
public int hashCode()
{
return wrappedType.hashCode();
}
}
Hello,
I'm having the same problem. Does anyone know how to add an debugId to the items/treenodes of a tree?
Old post but: in Vaadin, only components have debugIds.
To do things like selecting rows, you use itemIds, not debugIds.
DebugIds are only needed for things like interacting with JavaScript or for automated testing tools on the client side. You rarely need them in a normal application.