Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify a button to open an URL?

I want to write a web application that triggers the default email client of the user to send an email.

Thus, I created a Link, that leads to an URL conforming to the mailto URI scheme (http://en.wikipedia.org/wiki/Mailto):

Link emailLink = new Link("Send Email", 
    new ExternalResource("mailto:[email protected]"));

However, instead of using a Link, I want to provide a Button that allows to trigger the respective functionality. But, for buttons I cannot set an ExternalResource to be opened.

Does anybody know to solve this problem for Buttons, or how to create a Link that looks and behaves exactly like a button? I also tried some CCS modification but did not manage the task by myself. I also found some solutions for former Vaadin versions (https://vaadin.com/forum/#!/thread/69989), but, unfortunately they do not work for Vaadin 7.

like image 984
Claas Wilke Avatar asked Mar 12 '14 14:03

Claas Wilke


People also ask

How do you create a button that opens a link in HTML?

Conclusion. In HTML, a button link to another page can be by using the <a> tag, <input> tag, and the <form> tag. A link on a button is get by href=”” attribute of <a> tag. The “type=button” and “onclick=link” attributes are used to create a link on the button.

How do you reference a link in HTML?

The <a> tag defines a hyperlink, which is used to link from one page to another. The most important attribute of the <a> element is the href attribute, which indicates the link's destination. By default, links will appear as follows in all browsers: An unvisited link is underlined and blue.


2 Answers

For solving similar issue, I applied previously:

    String email="[email protected]";
    Link l=new Link();
    l.setResource(new ExternalResource("mailto:" + email));
    l.setCaption("Send email to " + email);
    addComponent(l);
like image 147
Oleksii Kyslytsyn Avatar answered Nov 08 '22 19:11

Oleksii Kyslytsyn


I remember solving a similar problem using a ResourceReference.

Button emailButton = new Button("Email");
content.addComponent(emailButton);
Resource res = new ExternalResource("mailto:[email protected]");
final ResourceReference rr = ResourceReference.create(res, content, "email");

emailButton.addClickListener(new Button.ClickListener() {

    @Override
    public void buttonClick(ClickEvent event) {
        Page.getCurrent().open(rr.getURL(), null);
    }
});
like image 44
kris54321 Avatar answered Nov 08 '22 19:11

kris54321