Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
book-of-vaadin.pdf
Скачиваний:
88
Добавлен:
24.03.2015
Размер:
13.43 Mб
Скачать

Writing a Server-Side Web Application

enabled (disabled by default), Vaadin closes the UIs and the session after the time specified in the session-timeout parameter expires after the last non-heartbeat request.

The closeIdleSessions parameter can be given to a servlet (not the web application) as follows:

<servlet>

...

<init-param> <param-name>closeIdleSessions</param-name> <param-value>true</param-value>

</init-param>

Cross-Site Request Forgery Prevention

Vaadin uses a protection mechanism to prevent malicious cross-site request forgery (XSRF or CSRF), also called one-click attacks or session riding, which is a security exploit for executing unauthorized commands in a web server.This protection is normally enabled. However, it prevents some forms of testing of Vaadin applications, such as with JMeter. In such cases, you can disable the protection by setting the disable-xsrf-protection parameter to true.

<context-param> <param-name>disable-xsrf-protection</param-name> <param-value>true</param-value>

</context-param>

4.8.5. Deployment Configuration

The Vaadin-specific parameters defined in the deployment configuration are available from the

DeploymentConfiguration object managed by the VaadinSession.

DeploymentConfiguration conf = getSession().getConfiguration();

// Heartbeat interval in seconds

int heartbeatInterval = conf.getHeartbeatInterval();

Parameters defined in the Java Servlet definition, such as the session timeout, are available from the low-level HttpSession or PortletSession object, which are wrapped in a WrappedSession in Vaadin.You can access the low-level session wrapper with getSession() of the VaadinSession.

WrappedSession session = getSession().getSession(); int sessionTimeout = session.getMaxInactiveInterval();

You can also access other HttpSession and PortletSession session properties through the interface, such as set and read session attributes that are shared by all servlets belonging to a particular servlet or portlet session.

Deployment Configuration

87

88

Chapter 5

User Interface

Components

5.1. Overview ..................................................................................................

90

5.2. Interfaces and Abstractions .....................................................................

91

5.3. Common Component Features ...............................................................

96

5.4. Component Extensions .........................................................................

107

5.5. Label .....................................................................................................

107

5.6. Link .......................................................................................................

110

5.7. TextField ...............................................................................................

112

5.8. TextArea ...............................................................................................

116

5.9. PasswordField ......................................................................................

118

5.10. RichTextArea ......................................................................................

118

5.11. Date and Time Input with DateField ....................................................

120

5.12. Button .................................................................................................

125

5.13. CheckBox ...........................................................................................

126

5.14. Selecting Items ....................................................................................

127

5.15. Table ....................................................................................................

139

5.16. Tree .....................................................................................................

157

5.17. MenuBar .............................................................................................

158

5.18. Embedded Resources .........................................................................

160

5.19. Upload ................................................................................................

162

5.20. ProgressIndicator ..............................................................................

164

Book of Vaadin

89

User Interface Components

 

5.21. Slider ...................................................................................................

166

5.22. Component Composition with CustomComponent ...........................

168

5.23. Composite Fields with CustomField ...................................................

169

This chapter provides an overview and a detailed description of all non-layout components in Vaadin.

Because of pressing release schedules to get this edition to your hands, we were unable to completely update this chapter for Vaadin 7. The content is up-to-date to a large extent, but some topics still require revision, especially the data binding of the Table component. Please consult the web version once it is updated, or the next print edition.

5.1. Overview

Vaadin provides a comprehensive set of user interface components and allows you to define custom components. Figure 5.1, “User Interface Component Class Hierarchy” illustrates the inheritance hierarchy of the UI component classes and interfaces. Interfaces are displayed in gray, abstract classes in orange, and regular classes in blue. An annotated version of the diagram is featured in the Vaadin Cheat Sheet.

At the top of the interface hierarchy, we have the Component interface. At the top of the class hierarchy, we have the AbstractComponent class. It is inherited by two other abstract classes: AbstractField, inherited further by field components, and AbstractComponentContainer, inherited by various container and layout components. Components that are not bound to a content data model, such as labels and links, inherit AbstractComponent directly.

The layout of the various components in a window is controlled, logically, by layout components, just like in conventional Java UI toolkits for desktop applications. In addition, with the CustomLayout component, you can write a custom layout as an XHTML template that includes the locations of any contained components. Looking at the inheritance diagram, we can see that layout components inherit the AbstractComponentContainer and the Layout interface. Layout components are described in detail in Chapter 6, Managing Layout.

Looking at it from the perspective of an object hierarchy, we would have a Window object, which contains a hierachy of layout components, which again contain other layout components, field components, and other visible components.

You can browse the built-in UI components of Vaadin library in the Sampler application of the Vaadin Demo. The Sampler shows a description, JavaDoc documentation, and a code samples for each of the components.

In addition to the built-in components, many components are available as add-ons, either from the Vaadin Directory or from independent sources. Both commercial and free components exist. The installation of add-ons is described in Chapter 17, Using Vaadin Add-ons.

Vaadin Cheat Sheet and Refcard

Figure 5.1, “User Interface Component Class Hierarchy” is included in the Vaadin Cheat Sheet that illustrates the basic relationship hierarchy of the user interface components and data binding classes and interfaces. You can download it at http://vaadin.com/book.

The diagram is also included in the six-page DZone Refcard, which you can find at https://vaadin.com/refcard.

90

Overview

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]