Book Image

Vaadin 7 Cookbook

Book Image

Vaadin 7 Cookbook

Overview of this book

Table of Contents (19 chapters)
Vaadin 7 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Adding click listener to the Link component


Vaadin provides support for the Link component. We can make hyperlinks via this component. References to locations are represented as resource objects. The Link component is a regular HTML hyperlink, that is, an <a href> anchor element that is handled natively by the browser. Unlike when clicking a Button, clicking a Link does not cause an event on the server side. However, if we need to cause an event we have two ways to do it. We will take a look at them in this recipe.

Getting ready

We create a Vaadin project with a topmost class named Demo.

public class Demo extends UI {…}

How to do it...

The first way to do it, is to use an instance of the class Button and set the CSS style to Reindeer.BUTTON_LINK. So we get a component that looks like a link that has listeners for catching events.

public class Demo extends UI {

  @Override
  public void init(VaadinRequest request) {
    Button button = new Button("Vaadin");
    button.addClickListener(new...