bookmarks.war

SPA bookmarks using # url element for navigation. This allow to navigate throughout service without reload whole page.


bookmarks

Browser notifies server about bookmark changes fires up the OnBookmark event on application class.


	/*
	 * Set color name on browser navigation back or forward or user set
	 * right color name after # at address bar.
	 */
	@OnBookmark
	public void bookmarkColor(Event event) {
		if (event.getBookmark() == null || "".equals(event.getBookmark())) {
			color.setSelectedIndex(0);
			msg.setText(null);
			setStyle(new Background(ColorName.White.color()));
		} else 
			displayColor(event.getBookmark(), true);
	}

User can change color by:

	/*
	 * Set color name getting from request parameter "color".
	 */
	@OnRequest
	public void requestColor(Event event) {
		HttpServletRequest request = (HttpServletRequest) event.getData();
		initColor = request.getParameter("color");
		if (initColor != null)
			displayColor(initColor, true);
	}

Here is example how to handle when application page was loaded on browser. You can do some actions on view initialization.

	/*
	 * Send selected bookmark name to browser bar.
	 */
	@OnLoad
	public void loaded() {
		Option op = color.getSelectedOption();
		if (op !=  null) {
			setBookmark(op.getValue());
		}
	}

Demo code you can get from here bookmarks.war