Getting data about requests
Submitted on 08 March 2012I confess, Vaadin 6 was good, but Vaadin 7 is even better. This article will detail most nastiness that is managed by this new version so that we only have to code a few lines to achieve our goals. One of such goal is the search of information about the request and the client.
In Vaadin 6, it was possible, but cumbersome for we had to force our application to implement the HttpServletRequestListener
interface. The interface let us access the servlet request (as well as the servlet response), and then we were on our own.
In Vaadin 7, the Vaadin team identified recurring needs to some piece of data and provided a Vaadin API to access them easily; for example:
- The user agent type and its version (major and minor)
- The user’s locale to initialize resources bundles
- The screen size, as well as the underlying viewpoint size to adapt the layour to the available space
- The URL fragment (#) to restore data
Vaadin 7 UI
’s init()
method takes a VaadinRequest
as a parameter, that is the entry point into these informations. Behold how we could address the above needs:
No more dirty plumbing into the ServletRequest
, welcome to a world of easy reading!
The ready-to-use WAR file is available here(sources included).
Tags: