如何在vaadin中点击链接设置值 [英] how to set value on click of link in vaadin

查看:162
本文介绍了如何在vaadin中点击链接设置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是vaadin的新手。我有一个链接像

I am new to vaadin. I have one Link like


链接链接=新链接(,新的ExternalResource(redirectURL));

Link link = new Link("", new ExternalResource(redirectURL));

我的要求是,我必须在用户点击链接时设置值。用户单击链接时是否可以添加侦听器。或者,如果单击链接,是否有其他设置值的方法。

my requirement is, I have to set value when user clicks the link. Can I add listener when user click the link. Or is there alternate ways of setting value if link is clicked.

推荐答案

要捕获链接或标签上的onClick,我总是创建一个 Horizo​​ntalLayout 并将组件放入其中:

To capture onClick on a link or a label, I always create a HorizontalLayout and put the component inside it:

HorizontalLayout hor = new HorizontalLayout();
final Link link = new Link("Click on Me!", new ExternalResource("http://www.google.com"));
hor.addComponent(link);
hor.addLayoutClickListener(new LayoutClickListener() {
    @Override
    public void layoutClick(LayoutClickEvent event) {
        // capture the click here and do whatever you'd like to do, e.g.
        // if ( event.getClickedComponent() != null ) {
        // if(event.getClickedComponent().equals(link)) {}
    }
});

这篇关于如何在vaadin中点击链接设置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆