Link

The Link class is used to create references to external or internal resources. When the user clicks the link, the server will open the resource in the target window of the link. Resources are explained in the section called “Referencing Resources”.

Links to external resources can be made by using an URI as follows:

main.addComponent(new Link ("link to a resource",
                            new ExternalResource("http://www.itmill.com/")));

With the simple contructor used in the above example, the link is opened in the current window. Using the constructor that takes the target window as a parameter, or by setting the window with setWindow, you can open the resource in another window, such as a native popup window or a FrameWindow. As the target window can be defined as a target string managed by the browser, the target can be any window, including windows not managed by the application itself.

When the user clicks the link, the application will receive an event regarding the click and handle it to provide the resource. The link is therefore not an <a href> element in HTML and it does not have an URI. This has some additional consequences, such as that a link can not be marked as "visited" by the browser, unlike normal hyperlinks. If you wish to have an actual HTML anchor element, you need to customize the rendering of the component or use a Label with XHTML content mode and write the anchor element by yourself.

Modifying the appearance of a link in a theme is often used to change the color or the underlining of the link. The link will be, by default, rendered as a div element that has classes "link pad clickable"", and it will contain a div element with caption class. You can therefore control the appearance with CSS selector ".itmtk .link .caption", for example as follows:

.itmtk .link .caption {
    border-bottom: 1px dotted green;
    color: green;
    font-style: normal;
}
.itmtk .link .over .caption {
    border-bottom: 1px solid red;
    background-color: #e0e0ff;
    color: red;
}

When the mouse pointer hovers over the link, it will have also the over class. Themes and custom CSS are detailed in Chapter 6, Themes.

Also the Button component can look like a link when you set its style as link. Please see the section called “Button” for more information.