gwt多页面应用程序 [英] gwt multi-page application

查看:115
本文介绍了gwt多页面应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要手动从一个页面切换到另一个页面的多页面应用程序。它可以在GWT中完成,因为它是针对单页面应用程序的。我正在从Google代码和在线论坛中学习,但找不到任何具有多个未通过共同入口点链接的多页面的应用程序。任何想法?

解决方案

GWT通过URL http://www.yourhost.vom/main#pagename ,其中pagename是表示应用内的页面的片段标识符。



这个页面(注意,浏览器从不真正重新加载页面,所以GWT应用程序保持不变),具有完整的历史记录支持并可加入书签。



注意:贯穿GWT文档片段标识符有时被称为地方标记或历史标记。 >


  1. 启用历史支持通过向您的主页添加iframe:

     < iframe src =javascript :''
    id =__ gwt_historyFrame
    style =width:0; height:0; border:0>
    < / iframe>


  2. 注册一个ValueChangeHandler,当FI(页面)发生变化时通知: History.addValueChangeHandler(..)。通过调用 History.newItem(newpage)转到特定的页面。在这个处理程序中,您放置了一个显示新页面的逻辑。

  3. (无#)
  4. 甚至可以通过将片段标识符分为子部分来将parameters传递给页面:for例如#edit / user4。只需解析此FI,调用显示编辑页面的代码并将user4传递给它。您可以使用任何字符将FI分成页面部分和参数部分(我在此使用/)。在现实生活中看到这一点:在Gmail中打开邮件并查看URL。



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 learning from the Google code and online forums but could not find any application which had multi-pages not linked by a common entry-point. Any ideas?

解决方案

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.

这篇关于gwt多页面应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆