gwt multi-page application

后端 未结 2 959
一生所求
一生所求 2020-12-29 15:29

I have a multipage application which needs to manually switched from one page to another. could it be done in GWT since it is targeted towards single page application. I am

相关标签:
2条回答
  • 2020-12-29 15:40

    While you can use GWT to switch pages, the resulting code will be slow and suboptimal, with the pages taking longer to load.

    0 讨论(0)
  • 2020-12-29 15:48

    GWT has support for "pages" within application via URL fragment identifier (FI), i.e. http://www.yourhost.vom/main#pagename, where "pagename" is a fragment identifier representing a "page" within your app.

    This "pages" (note that browser never really reloads the page, so GWT app stays the same), have full history support and are bookmarkable.

    NOTE: throughout GWT docs fragment identifier is sometimes referred to as place token or history token.

    1. Enable history support by adding an iframe to your host page:

      <iframe src="javascript:''" 
              id="__gwt_historyFrame" 
              style="width:0;height:0;border:0">
      </iframe>
      
    2. Register a ValueChangeHandler to be notified when FI (page) changes: History.addValueChangeHandler(..). Within this handler you put a logic that displays the new page.

    3. Go to a particular page by calling History.newItem("newpage") (without #)

    4. You can even pass "parameters" to page, by dividing fragment identifier into sub parts: for example "#edit/user4". Just parse this FI, invoke code that shows edit page and pass "user4" to it. You can use any character to divide FI into a "page" part and "parameter" part (I use "/" here). To see this in real life: open a message in gmail and look at URL.

    0 讨论(0)
提交回复
热议问题