Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Accessing nested components
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
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!!
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.
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
Set applications main window to be mainWindow
Wait a while
Access text area in mainWindow->Panel->HorizontalLayout->TextArea
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.
Thanks for the pointer to the (obvious) tutorial! Thanks also to Tam.