History handling

Hi,

I’m trying to implement a small test program with a history. But it doesn’t work.

final TabSet tabSet = new TabSet(); 
tabSet.addTabSelectedHandler(new TabSelectedHandler(){

	@Override
	public void onTabSelected(TabSelectedEvent event) {
		History.newItem("tab-" + event.getID());
	}
});

Tab tTab1 = new Tab("Y");
tTab1.setID("0");
Tab tTab2 = new Tab("X");
tTab2.setID("1");

History.addValueChangeHandler(new ValueChangeHandler<String>() {
	public void onValueChange(ValueChangeEvent<String> event) {
		String historyToken = event.getValue();

		// Parse the history token
		try {
			if (historyToken.substring(0, 4).equals("tab-")) {
				String tabIndexToken = historyToken.substring(4, 5);
				int tabIndex = Integer.parseInt(tabIndexToken);
				// Select the specified tab panel
				tabSet.selectTab(tabIndex);
			} else {
				tabSet.selectTab(0);
			}

		} catch (IndexOutOfBoundsException e) {
			tabSet.selectTab(0);
		}
	}
});

Where can be errors? Or it shouldn’t work with a tab selection?

Thanks beforehand.

SmartGWT uses the standard GWT history API’s and functionality. The Showcase uses it with tabs. Have a look at it. If you’re still not able to figure it out, try reading the GWT documentation or searching the GWT Google Groups.

Sanjiv