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.
Accessing nested components
HI,
I'm having a problem which may be a paradigm shift from php/DOM. How do I access nested components?
If I have the following layout
application
mainWindow
Panel
Horizontal Layout
TextArea
How would I access the TextArea caption and update it? Do I need to get an iterator over each container (mainWindow, Panel, HorizontalLayout) and check the names to get down to the TextArea? If I use a Listener on the TextArea - how can I call the event from (say) the application scope?
This seems dumb, but it's doing my head in!!
Cheers
Andy
Hi Andy,
I don't know if you are working in only one class or not, so I'll suppose that we are working in only one class with panel, horizontal layout and textarea. In this case, you can access textarea like this:
//Panel initialization or something to get your panel
...
HorizontalLayout myLayout = (HorizontalLayout )panel.getLayout();
TextArea myTextArea = (TextArea)myLayout.getComponent(0);// if you know exactly the index of your text area
myTextArea.setCaption("My Caption");
Hope this will help you.
TamNguyen
HI,
Thanks for the reply. It helps a bit, but I'm using separate classes. Ideally what I'd like to do is build the inferface in one class then manipulate it from another class such as the main application class. In pseudo code I'd like to do this:
TestApp extends Application
{
Create mainWindow
Set applications main window to be mainWindow
Display mainWindow
Wait a while
Access text area in mainWindow->Panel->HorizontalLayout->TextArea
...
}
Cheers
Andy
The 5 minutes tutorial is almost what you are trying to do.
It is better not to look for components by layout structure otherwise you will need to redo all your code every time you want to change your web page structure.
The tutorial keeps all important component directly into the Application class. While this works it is not flexible for more complex websites, continue reading the tutorial to see how to manage views and switch between them.
The tutorial is here with the source code.
Hi,
Thanks for the pointer to the (obvious) tutorial! Thanks also to Tam.
Andy