- com.vaadin.ui.UI : a HTML component, may be entire web page, or just part of it.
- static UI.getCurrent() - thread-local, UI for the currently processed request
- getPage() - get the page for the UI
- Page : represents the web page and the browser window
- static Page.getCurrent() - page for the currently processed request, = UI.getCurrent().getPage()
- VaadinSession : user session
- static VaadinSession.getCurrent() obtains the session
- Components :
- laid out by layout component
- user interaction causes events
- Field components are intended for input and haling of data
- getUI() : note not available in constructor
- getPage() : note, not available in constructor
- Event and listeners
- server push is also possible
- Resources
- Themes
- Data binding
- property - for a field
- item - for multiple fields to bind to properties of an item
- container - a collection of multiple items
Building UI
- layout first : new layout; setSizeFull(); this.setContent(new layout);
- components: layout.addComponent(new component)...
Application Architecture
- 4.2.2 Composite components : extend CustomComponent to create custom component
- this.setCompositionRoot(a layout, with added components...)
- setSizeFull();
- 4.2.3 View Navigation : Navigator - a view manager, manage view navigation and URI fragment enabling bookmarking, linking, history going back
- Section 11.2 - embedding UI in web pages
Implementing Event / Listeners
- recommended - implement with anonymous class, without need to distinguish event source (because only be used in one place for one source); the component being listened must be declared "final"
Image, downloadable files and other resources
- Image - component
- Flash - Flash component
- BrowserFrame - embeded browser frame
- Embedded - others embedded resources
- Link - provide downloadable files
- StreamResource - dynamically created resource
- RequestHandler - dynamic resource
- Resource interface and classes
- ConnectorResource
- FileResource - file in file system
- ClassResource - class loader
- StreamResource - can be used to create dynamic image, report, etc
- ThemeResource
- ExternalResource
Error handling
- All component has built-in error indicator
- automatically turned on when validation fails
- setComponentError() - explicitly set
- System messages - notification indicating major invalidity (most commonly - session timeout)
- properties : short caption, message, url to redirect after displaying, enabled / disabled
- can be customized by setting SystemMessagesProvider in VaadinService
- Uncaught Exceptions
- DefaultErrorHandler handles uncaught exceptions
- display as component error
- Custom error handling
- Implement custom ErrorHandler, or extend DefaultErrorHandler
- and enable with setErrorHandler() in any components or in VaadinSession object
- Notifications
- error or information appear briefly
- static Notification.show()
- new Notification("bala bala bala", Notification.TYPE_xxx, true/false HTML content).show(Page.getCurrent());
- Application Lifecycle
- Deploy, undeploy, redeploy, @PreserveOnRefresh... see doc
- Customizing Vaadin servlet
- overriding servletInitialized() method
- first call super.servletInitialized()
- VaadinService can be obtained with getService();
- User session
- getSession() with a UI
- static VaadinSession.getCurrent();
- handling user session initialization and destruction: see sample code @4.7.3
- Loading a UI
- when new UI is created, its init() method is called, request is provided to the method
- custom UI provider - see doc
- preserving UI on refresh - see doc
- UI expiration
- client sends keep-alive to keep UI open
- by default, (heartbeatInterval in servelet) heartbeats interval = 5min
- DetachEvent is sent to all DetachListeners to the UI when cleanup happens
- when detach, detach() is called
- Session Expiration
- kept open by request and heartbeat
- can be configured
- Session close
- VaadinSession.close()
- typically redirect user to another URL by Page.setLocation()
- Deploying an application
- operation and content organization, see doc
- web servlet class and annotation - see doc
- web.xml - see doc
- servlet API version
- widget set
- servlet mapping, map sub-paths
- production mode (by default, debug mode) - disable debugging features
- custom UI provider
- UI heartbeat
- session timeout
- push mode
- cross-site
- DeploymentConfiguration = VaadinSession.getConfiguration(), obtain configurations