通过 Vaadin 中的链接打开弹出窗口

问题描述:

我在我的应用程序中使用 Vaadin 框架.我想使用 Vaadin Link 打开一个弹出屏幕.我知道通过按钮打开弹出窗口,但我需要通过链接打开弹出窗口.任何人都可以帮忙,这是我的代码:

I am Using Vaadin Framework in my application. I want to open a popup screen using Vaadin Link. I know to open popup thrugh button but I need to open popup through Link. Can anybody help, this is my code:

Link link1 = new Link(String.valueOf(rs.getInt(1)), new ExternalResource("#")); 

_reportTable.getItem(dashboardDataRowId)
.getItemProperty("todo").setValue(link1);

Vaadin 之书 - 组件 - 链接,链接应该仅用于指向外部资源的超链接,因为它只不过是锚定 html 标签的包装器,因此它不会触发任何服务器端事件.因此,您无法在服务器端做出反应以打开弹出窗口或执行其他一些逻辑.

As explained in in Book of Vaadin - Components - Link, Link should be used only for hyperlinks to external resources, as it is nothing more than a wrapper for a anchor html tag and as such it does not fire any server side events. As a result you cannot react on server side to open a popup window or do some other logic.

Link 是一个普通的 HTML 超链接,也就是一个锚点由浏览器本地处理的元素.与点击时不同一个按钮,点击一个链接不会在服务器端引发事件.

The Link is a regular HTML hyperlink, that is, an 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.

您真正想要的是样式为超链接的 vaadin 按钮.您可以通过创建一个常规按钮(它支持服务器端事件并可以打开您的弹出窗口)然后添加适当的样式来实现.

What you really want is vaadin button styled as a hyperlink. You can do it by creating a regular button (which supoorts server side events and can open your popup) and then adding an appropriate style.

Button linkButton = new Button();
linkButton .setStyleName(BaseTheme.BUTTON_LINK);

始终确保调用 addStyleName() 而不是 setStyleName(),因为它只会将您的新样式添加到已存在的其他样式列表中,并且不会使用您唯一的新样式覆盖该列表.

Always be sure to call addStyleName() instead of setStyleName() as it only adds your new style to the list of other styles already present and it does not override that list with your only new style.