Search in sources :

Example 1 with HasUrlParameter

use of com.vaadin.flow.router.HasUrlParameter in project flow by vaadin.

the class NavigationStateRenderer method notifyNavigationTarget.

@Override
protected void notifyNavigationTarget(Component componentInstance, NavigationEvent navigationEvent, BeforeEnterEvent beforeEnterEvent, LocationChangeEvent locationChangeEvent) {
    if (!(componentInstance instanceof HasUrlParameter)) {
        return;
    }
    NavigationState navigationState = getNavigationState();
    Class<? extends Component> routeTargetType = navigationState.getNavigationTarget();
    List<String> parameters = navigationState.getUrlParameters().orElse(null);
    Object deserializedParameter = null;
    try {
        deserializedParameter = ParameterDeserializer.deserializeRouteParameters(routeTargetType, parameters);
    } catch (Exception e) {
        beforeEnterEvent.rerouteToError(NotFoundException.class, String.format("Failed to parse url parameter, exception: %s", e));
        return;
    }
    HasUrlParameter<Object> hasUrlParameter = (HasUrlParameter<Object>) componentInstance;
    hasUrlParameter.setParameter(beforeEnterEvent, deserializedParameter);
}
Also used : NavigationState(com.vaadin.flow.router.NavigationState) NotFoundException(com.vaadin.flow.router.NotFoundException) NotFoundException(com.vaadin.flow.router.NotFoundException) HasUrlParameter(com.vaadin.flow.router.HasUrlParameter)

Aggregations

HasUrlParameter (com.vaadin.flow.router.HasUrlParameter)1 NavigationState (com.vaadin.flow.router.NavigationState)1 NotFoundException (com.vaadin.flow.router.NotFoundException)1