private <C> void navigate(final PageNode<C> toPageInstance, final Multimap<String, String> state) { final HistoryToken token = historyTokenFactory.createHistoryToken(toPageInstance.name(), state); logger.debug("Navigating to " + toPageInstance.name() + " at url: " + token.toString()); navigate(new Request<>(toPageInstance, token), true); }
private <C> void navigate(final PageNode<C> toPageInstance, final Multimap<String, String> state) { final HistoryToken token = historyTokenFactory.createHistoryToken(toPageInstance.name(), state); logger.debug("Navigating to " + toPageInstance.name() + " at url: " + token.toString()); navigate(new Request<>(toPageInstance, token), true); }
@Produces @ApplicationScoped public URLPatternMatcher createURLPatternMatcher(NavigationGraph navGraph) { URLPatternMatcher patternMatcher = new URLPatternMatcher(); Collection<PageNode<?>> pages = navGraph.getAllPages(); for(PageNode<?> page : pages) { patternMatcher.add(page.getURL(), page.name()); } if (!navGraph.isEmpty()) { PageNode<?> defaultPageNode = navGraph.getPageByRole(DefaultPage.class); patternMatcher.setAsDefaultPage(defaultPageNode.name()); } return patternMatcher; }
@Produces @ApplicationScoped public URLPatternMatcher createURLPatternMatcher(NavigationGraph navGraph) { URLPatternMatcher patternMatcher = new URLPatternMatcher(); Collection<PageNode<?>> pages = navGraph.getAllPages(); for(PageNode<?> page : pages) { patternMatcher.add(page.getURL(), page.name()); } if (!navGraph.isEmpty()) { PageNode<?> defaultPageNode = navGraph.getPageByRole(DefaultPage.class); patternMatcher.setAsDefaultPage(defaultPageNode.name()); } return patternMatcher; }
/** * Update the state of your existing page without performing a full navigation. * <br/> * This will perform a pseudo navigation updating the history token with the new states. */ public void updateState(Multimap<String, String> state) { if(currentPage != null) { currentPageToken = historyTokenFactory.createHistoryToken(currentPage.name(), state); HistoryWrapper.newItem(currentPageToken.toString(), false); currentPage.pageUpdate(currentComponent, currentPageToken); } else { logger.error("Cannot update the state before a page has loaded."); } }
/** * Update the state of your existing page without performing a full navigation. * <br/> * This will perform a pseudo navigation updating the history token with the new states. */ public void updateState(Multimap<String, String> state) { if(currentPage != null) { currentPageToken = historyTokenFactory.createHistoryToken(currentPage.name(), state); HistoryWrapper.newItem(currentPageToken.toString(), false); currentPage.pageUpdate(currentComponent, currentPageToken); } else { logger.error("Cannot update the state before a page has loaded."); } }
/** * Looks up the PageNode instance that provides content for the given widget type, sets the state on that page, then * makes the widget visible in the content area. * * @param toPage * The content type of the page node to look up and display. Normally, this is a Widget subclass that has * been annotated with {@code @Page}. * @param state * The state information to set on the page node before showing it. Normally the map keys correspond with the * names of fields annotated with {@code @PageState} in the widget class, but this is not required. */ public <C> void goTo(final Class<C> toPage, final Multimap<String, String> state) { PageNode<C> toPageInstance = null; try { toPageInstance = navGraph.getPage(toPage); navigate(toPageInstance, state); } catch (final RedirectLoopException e) { throw e; } catch (final RuntimeException e) { if (toPageInstance == null) // This is an extremely unlikely case, so throwing an exception is preferable to going through the navigation error handler. throw new PageNotFoundException("There is no page of type " + toPage.getName() + " in the navigation graph."); else navigationErrorHandler.handleInvalidPageNameError(e, toPageInstance.name()); } }
/** * Looks up the PageNode instance that provides content for the given widget type, sets the state on that page, then * makes the widget visible in the content area. * * @param toPage * The content type of the page node to look up and display. Normally, this is a Widget subclass that has * been annotated with {@code @Page}. * @param state * The state information to set on the page node before showing it. Normally the map keys correspond with the * names of fields annotated with {@code @PageState} in the widget class, but this is not required. */ public <C> void goTo(final Class<C> toPage, final Multimap<String, String> state) { PageNode<C> toPageInstance = null; try { toPageInstance = navGraph.getPage(toPage); navigate(toPageInstance, state); } catch (final RedirectLoopException e) { throw e; } catch (final RuntimeException e) { if (toPageInstance == null) // This is an extremely unlikely case, so throwing an exception is preferable to going through the navigation error handler. throw new PageNotFoundException("There is no page of type " + toPage.getName() + " in the navigation graph."); else navigationErrorHandler.handleInvalidPageNameError(e, toPageInstance.name()); } }
/** * Initialize the anchor's href attribute. * * @param toPage * The page type this transition goes to. Not null. * @param state * The page state. Cannot be null (but can be an empty multimap) */ private void initHref(Class<P> toPage, Multimap<String, String> state) { PageNode<P> toPageInstance = navigation.getNavGraph().getPage(toPage); HistoryToken token = htFactory.createHistoryToken(toPageInstance.name(), state); String href = "#" + token.toString(); setHref(href); }
/** * Initialize the anchor's href attribute. * * @param toPage * The page type this transition goes to. Not null. * @param state * The page state. Cannot be null (but can be an empty multimap) */ private void initHref(Class<P> toPage, Multimap<String, String> state) { PageNode<P> toPageInstance = navigation.getNavGraph().getPage(toPage); HistoryToken token = htFactory.createHistoryToken(toPageInstance.name(), state); String href = "#" + token.toString(); setHref(href); }