How can I do bookmarking in GWT with user search queries -
i newbie gwt, did enough search understand can use history mechanism bookmarking in gwt.
but still confused how can bookmarking when need apply them user search queries. e.g. main page may have several tabs ( can use history mechanism here bookmark tab). after user navigates particular tab , performs search query. if wish bookmark search result url, how can gwt.
some options tried: gwt hyperlinks widgets , anchors, urlbuilder not sure convenient one.
any inputs appreciated.
you should read docs on gwt history here.
as example case, let's want remember tab user on (parameter t) , query user has searched (parameter q). put in url
t=2&q=hello
then when gwt module loading. check url see if these parameters here. if yes, parse them load correct tab , search. if not, load scratch. sample theoretical code :
private int selectedtab; private string query; public void onmoduleload() { string token = history.gettoken(); if (!strings.isnullorempty(token)) { // parse history token string t = token.substring(2,3); string q = token.substring(6, token.length()); int tabindex = integer.valueof(t); setselectedtab(tabindex); search(q); } else { // init scratch setselectedtab(0); } // add listener tab panel, change history token everytime tab changes tabpanel.addselectionhandler(new selectionhandler<integer>(){ public void onselection(selectionevent<integer> event) { selectedtab = event.getselecteditem(); setselectedtab(selectedtab); changehistorytoken(); }}); // add listeners search query stuff } private void changehistorytoken() { history.newitem("t=" + selectedtab + "&q=" + query); } private void setselectedtab(int index) { // set selected tab } the point of is, everytime state of application changes, add new item history. item string represents state of application. then, when load application, check see if token here. if is, initialize application parsing token , setting correct values (selected tab, search query, whatever else). if there no history token, init default values.
don't forget enable history support adding iframe page :
<iframe src="javascript:''" id="__gwt_historyframe" style="width:0;height:0;border:0"></iframe>
Comments
Post a Comment