How I can get all components in Vertical Layout?

Hi!

I need help.
How I can get all components in Vertical Layout?

VerticalLayout main = new VerticalLayout(); main.addComponent(new TextField("1")); main.addComponent(new TextField("2")); main.addComponent(new TextField("3")); List<AbstractComponent> list = main.getAllComponents(); //How?? I use Vaadin 7

You can do (at least in Vaadin 7):

for (int i = 0; i < layout.getComponentCount(); i++) { Component c = layout.getComponent(i); //at this point you can do it to do whatever like: if(c instanceof TextField){ TextField txtfield = (TextField) c; txtfield.setValue("somestring"); } } layout would be main in your case.

Thanks, I stopped on this variant, but maybe exist more right variant…

No, isn’t it. If you are using apache commons-colllections you could use this to do the same.

List<Component> components = IteratorUtils.toList(main.iterator());

I like this variant, but include to Maven full jar for one class… I don’t know… Is this a good idea?

Well it essentially does something like this:

for (Iterator<Component> iterator = layout.iterator(); iterator.hasNext();) { Component comp = (Component) iterator.next(); } which wouldn’t require another jar.