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

Advanced Web Application Topics

often causes more warnings from its child components. A good rule of thumb is to work on the upper-level problems first and only after that worry about the warnings from the children.

Figure 11.3. Debug Window Showing the Result of Analyze layouts.

11.3.3. Custom Layouts

CustomLayout components can not be analyzed in the same way as other layouts. For custom layouts, the Analyze layouts button analyzes all contained relative-sized components and checks if any relative dimension is calculated to zero so that the component will be invisible. The error log will display a warning for each of these invisible components. It would not be meaningful to emphasize the component itself as it is not visible, so when you select such an error, the parent layout of the component is emphasized if possible.

11.3.4. Debug Functions for Component Developers

You can take advantage of the debug mode when developing client-side components. The static function ApplicationConnection.getConsole() will return a reference to a VConsole object which contains logging methods such as log(String msg) and error(String msg). These functions will print messages to the Debug Window and Firebug console in the same way as other debugging functionalities of Vaadin do. No messages will be printed if the Debug Window is not open or if the application is running in production mode.

11.4. Request Handlers

Request handlers are useful for catching request parameters or generating dynamic content, such as HTML, images, PDF, or other content. You can provide HTTP content easily also with stream resources, as described in Section 4.4.5, “Stream Resources”. The stream resources, however, are only usable from within a Vaadin application, such as in an Image component. Request handlers allow responding to HTTP requests made with the application URL, including GET or POST parameters. You could also use a separate servlet to generate dynamic content, but a request handler is associated with the Vaadin session and it can easily access all the session data.

To handle requests, you need to implement the RequestHandler interface. The handleRequest() method gets the session, request, and response objects as parameters.

If the handler writes a response, it must return true. This stops running other possible request handlers. Otherwise, it should return false so that another handler could return a response. Eventually, if no other handler writes a response, a UI will be created and initialized.

In the following example, we catch requests for a sub-path in the URL for the servlet and write a plain text response. The servlet path consists of the context path and the servlet (sub-)path.

Custom Layouts

289

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