我目前有一个显示 SomeModel 类型内容的网格.当我单击该 Grid 的条目时,我想导航到一个视图,该视图将对象作为其输入以显示条目内容.
I currently have a grid that displays content of type SomeModel.
When I click an entry of that Grid I would like to navigate to a view that takes an object as its input to display the entries content.
为了实现这种行为,我创建了一个 DetailLayout,如下所示:
To achive this behaviour I created a DetailLayout like this:
public DetailLayout extends FlexLayout implements HasUrlParameter<SomeModel>{
/* skipped some details */
@Override
public void setParameter(BeforeEvent event, Host parameter) {
/* This is where I expected to be able to handle the object */
}
}
从 Grid 我尝试像这样导航:
From within the Grid I tried to navigate like this:
addSelectionListener((event) -> {
event.getFirstSelectedItem().ifPresent(somemodel -> {
getUI().ifPresent(ui -> {
ui.navigate(DetailLayout.class, somemodel);
});
});
});
但不幸的是,即使它的语法非常好,Vaadin 也不支持这种行为.
But unfortunately this behaviour is not supported by Vaadin even tho its syntax is perfectly fine.
您是否知道在导航时传递对象的另一种方法,或者我是否错过了官方文档的某个部分 文档 ?
Do you know of another way to pass an object while navigation or did I miss a certain part of the official documentation documentation ?
提前谢谢你
如其他答案的评论中所述,如果您不希望将 ID 值作为URL,然后使用 Vaadin 提供的键值集合在幕后工作.
As discussed in the comments on the other Answer, if you do not wish to expose the ID value as part of the URL, then work behind the scenes by using the key-value collection provided by Vaadin.
Vaadin 实际上提供了三个范围级别的键值集合:
Vaadin actually provides key-value collections at three levels of scope:
通过 getAttribute & 在 VaadinContext 上可以使用应用范围的键值集合setAttribute 方法.
The app-wide key-value collection is available on the VaadinContext, via getAttribute & setAttribute methods.
VaadinService.getCurrent().getContext().setAttribute( key , value ) ;
每个用户的键值集合在 VaadinSession 上可用,通过 getAttribute &setAttribute 方法.
The per-user key-value collection is available on the VaadinSession, via getAttribute & setAttribute methods.
VaadinSession.getCurrent().setAttribute( key , value ) ;
➥ 每个浏览器窗口/选项卡的集合(您在本问题中想要满足您的需求)并不那么容易获得.你必须经过一个间接的步骤.在 ComponentUtil 类,调用 setData &getData 方法.除了 传递你的key和你的值,传递当前的UI对象.
➥ The per-browser-window/tab collection (what you want for your needs in this Question) is not quite so readily available. You have to go through an indirect step. On the ComponentUtil class, call setData & getData methods. In addition to passing your key and your value, pass the current UI object.
Component c = UI.getCurrent() ;
String key = "com.example.acmeapp.selectedProductId" ;
Object value = productId ;
ComponentUtil.setData( c , key , value ) ;
<小时>
请投票给我的 ticket #6287,一个功能请求添加 <UI 类的 code>setAttribute/getAttribute 方法,以匹配 VaadinSession 和 VaadinContext 的方法.
Please vote for my ticket # 6287, a feature-request to add setAttribute/getAttribute methods on UI class, to match those of VaadinSession and VaadinContext.
这篇关于Vaadin(流):使用共享对象导航到目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Java从数组中删除重复项?Java Remove Duplicates from an Array?(Java从数组中删除重复项?)
如何修复调用失败来自服务器的意外响应:在 AnHow to fix Invocation failed Unexpected Response from Server: Unauthorized in Android studio(如何修复调用失败来自服务器的意外响应:在
AES 加密,解密文件中有多余的垃圾字符AES encryption, got extra trash characters in decrypted file(AES 加密,解密文件中有多余的垃圾字符)
AES 错误:给定的最终块未正确填充AES Error: Given final block not properly padded(AES 错误:给定的最终块未正确填充)
在 JAVA 中使用 AES/GCM 检测不正确的密钥Detecting incorrect key using AES/GCM in JAVA(在 JAVA 中使用 AES/GCM 检测不正确的密钥)
Java 中的 AES-256-CBCAES-256-CBC in Java(Java 中的 AES-256-CBC)