Vaadin Flow:在onAttach期间获取当前的QueryParameters

问题描述 投票:1回答:1

如何在QueryParameters期间可靠地检索onAttach

情况:

我的组件需要这些参数用于配置目的,并且在beforeEnter期间需要获取相同信息的初始加载期间不会调用.getLocation(方便地具有onAttach)。


注意:

由于某种原因,VaadinRequest.getCurrent()返回null

request vaadin query-parameters vaadin-flow
1个回答
1
投票

即使AttachEvent不知道Location BeforeEventsetParameter

解决方法(简化):

@Route("workaround")
public class Workaround extends FlexLayout implements AttachNotifier, HasUrlParameter<String> {
    private Location currentLocation = null;

    /* ... */

    @Override
    public void setParameter(BeforeEvent event, @OptionalParameter String parameter) {
        // called before onAttach
        currentLocation = event.getLocation();
    }

    @Override
    protected void onAttach(AttachEvent attachEvent) {
        super.onAttach(attachEvent);

        QueryParameters qm = currentLocation.getQueryParameters();
        /* ... */
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.