There are a couple of problems here: 1. the post should be in http://groups.google.com/group/google-web-toolkit, not here 2. first advice : try coding the HyperlinkN (in your case N=1,2,3 from snippet above) in a SINGLE generic class. That way the code will be greatly reduced and better understood. 3. 2nd advice : why do your hyperlinks implement both EntryPoint and HistoryListener ? This means that all 3 of them are completely independent GWT modules, so I would imagine that history is not working there. 4. last advice : do not load multiple GWT modules, and NEVER call onModuleLoad (), this is NOT your job.
So, what you need to do: - change the hyperlink classes so that they don't implement entry point and they are generic (to just instantiate with a single line of code) - use just ONE EntryPoint and enable History there (for a single module) On Sep 18, 8:47 am, kris <[email protected]> wrote: > Hi Group, > > This is Krishna. I need to implement the concept of > HistoryListener in my project. For that I tried to implement small > example. > > I have taken 3 pages each containing Hyperlink say > HyperLink1,HyperLink2,HyperLink3. On click on each hyperlink It has to > redirect to other page. by using History Concept. > > Problem :History is not maintaining properly if I click on Back or > Forward Button. > > Actual Outcome: > > It has to redirect to the proper page by maintaining History > Concept. > > For that I tried with the following Snippet. > > Page1 Snippet : > ------------------------ > > import com.google.gwt.core.client.EntryPoint; > import com.google.gwt.user.client.History; > import com.google.gwt.user.client.HistoryListener; > import com.google.gwt.user.client.Window; > import com.google.gwt.user.client.ui.ClickListener; > import com.google.gwt.user.client.ui.Hyperlink; > import com.google.gwt.user.client.ui.Label; > import com.google.gwt.user.client.ui.RootPanel; > import com.google.gwt.user.client.ui.VerticalPanel; > import com.google.gwt.user.client.ui.Widget; > > public class Sample implements EntryPoint, HistoryListener > { > VerticalPanel panel = new VerticalPanel(); > String oldToken = null; > public void onModuleLoad() { > // TODO Auto-generated method stub > Hyperlink h = new Hyperlink(); > h.setText("HyperLink1"); > h.setTargetHistoryToken("HyperLink1"); > h.addClickListener(new ClickListener(){ > > public void onClick(Widget sender) { > // TODO Auto-generated method stub > panel.clear(); > HyperLink1 p = new HyperLink1(); > p.onModuleLoad(); > }}); > panel.add(h); > RootPanel.get().add(panel); > History.addHistoryListener(this); > } > > public void onHistoryChanged(String historyToken) { > > // TODO Auto-generated method stub > // TODO Auto-generated method stub > // If they are the same, no need to do anything > if (oldToken != null && historyToken.equals(oldToken)) > return; > > // Save the token for the next time round > oldToken = historyToken; > > // Get the tab index > if(historyToken.equals("HyperLink2")){ > panel.clear(); > HyperLink2 p = new HyperLink2(); > p.onModuleLoad(); > } > else > if(historyToken.equals("HyperLink3")){ > panel.clear(); > Sample p = new Sample(); > p.onModuleLoad(); > } > } > > } > > Page2 Snippet : > ---------------------- > > import com.google.gwt.user.client.History; > import com.google.gwt.user.client.HistoryListener; > import com.google.gwt.user.client.ui.ClickListener; > import com.google.gwt.user.client.ui.Hyperlink; > import com.google.gwt.user.client.ui.Label; > import com.google.gwt.user.client.ui.RootPanel; > import com.google.gwt.user.client.ui.VerticalPanel; > import com.google.gwt.user.client.ui.Widget; > import com.gwtext.client.widgets.Panel; > > public class HyperLink1 extends Panel implements HistoryListener > { > VerticalPanel panel = new VerticalPanel(); > String oldToken = null; > public void onModuleLoad() { > // TODO Auto-generated method stub > Hyperlink h = new Hyperlink(); > h.setText("HyperLink2"); > h.setTargetHistoryToken("HyperLink2"); > h.addClickListener(new ClickListener(){ > > public void onClick(Widget sender) { > // TODO Auto-generated method stub > panel.clear(); > HyperLink2 p = new HyperLink2(); > p.onModuleLoad(); > }}); > panel.add(h); > RootPanel.get().add(panel); > History.addHistoryListener(this); > } > > public void onHistoryChanged(String historyToken) { > > // TODO Auto-generated method stub > if (oldToken != null && historyToken.equals(oldToken)) > return; > > // Save the token for the next time round > oldToken = historyToken; > > // Get the tab index > if(historyToken.equals("HyperLink2")){ > panel.clear(); > HyperLink2 p = new HyperLink2(); > p.onModuleLoad(); > } > else > if(historyToken.equals("HyperLink3")){ > panel.clear(); > Sample p = new Sample(); > p.onModuleLoad(); > } > } > > } > > Page 3 Snippet : > ------------------------ > > import com.google.gwt.core.client.EntryPoint; > import com.google.gwt.user.client.History; > import com.google.gwt.user.client.HistoryListener; > import com.google.gwt.user.client.ui.ClickListener; > import com.google.gwt.user.client.ui.Hyperlink; > import com.google.gwt.user.client.ui.RootPanel; > import com.google.gwt.user.client.ui.VerticalPanel; > import com.google.gwt.user.client.ui.Widget; > > public class HyperLink2 implements EntryPoint, HistoryListener{ > VerticalPanel panel = new VerticalPanel(); > String oldToken = null; > public void onModuleLoad() { > // TODO Auto-generated method stub > Hyperlink h = new Hyperlink(); > h.setText("HyperLink3"); > h.setTargetHistoryToken("HyperLink3"); > h.addClickListener(new ClickListener(){ > > public void onClick(Widget sender) { > // TODO Auto-generated method stub > panel.clear(); > Sample m = new Sample(); > m.onModuleLoad(); > }}); > panel.add(h); > RootPanel.get().add(panel); > History.addHistoryListener(this); > } > > public void onHistoryChanged(String historyToken) { > > // TODO Auto-generated method stub > if (oldToken != null && historyToken.equals(oldToken)) > return; > > // Save the token for the next time round > oldToken = historyToken; > > // Get the tab index > if(historyToken.equals("HyperLink1")){ > panel.clear(); > HyperLink1 p = new HyperLink1(); > p.onModuleLoad(); > } > else > if(historyToken.equals("HyperLink3")){ > panel.clear(); > Sample p = new Sample(); > p.onModuleLoad(); > } > } > > } > > If you need further information Please let me know in advance. > > Thanks in advance for your earliest reply..... --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
