简体   繁体   English

使用Eclipse和GWT在Java中进行多页面开发

[英]Multiple Page Development in Java with Eclipse and GWT

I have been writing some basic code for an application I am designing. 我一直在为我正在设计的应用程序编写一些基本代码。 I have learned the basics and gotten some simple database connection working with RPC calls etc. What I need to do now and am completely lost (as I am traditionally a c# developer with windows forms). 我已经学习了基础知识并得到了一些简单的数据库连接,使用RPC调用等。我现在需要做什么而且完全丢失了(因为我传统上是一个带有Windows窗体的c#开发人员)。

In c# if I wanted a new form I would just create it, and then call the show method. c#中,如果我想要一个新表单,我将创建它,然后调用show方法。

How does one create multiple pages in GWT , and switch between them? 如何在GWT中创建多个页面,并在它们之间切换?

Thanks in advance, Chris 谢谢,克里斯

The simplest way would be to 最简单的方法是

  1. Make a new java class (GwtHome.java, GwtHelp.java etc) 创建一个新的java类(GwtHome.java,GwtHelp.java等)
  2. Extend these classes by using the Composite class 使用Composite类扩展这些类
  3. Make the equivalent of a Master Page and add it to the rootPanel as a class with the appropriate headers, menu, footer and Content Placeholder (Could be any of the AbsolutePanel, VerticalPanel, HorizontalPanel objects provided by the GWT Framework) 制作相当于母版页并将其作为具有相应标题,菜单,页脚和内容占位符的类添加到rootPanel(可以是GWT框架提供的任何AbsolutePanel,VerticalPanel,Horizo​​ntalPanel对象)
  4. By clicking on the menu clear the Placeholder and add the appropriate object of GwtHome, GwtHelp etc. 通过单击菜单清除占位符并添加GwtHome,GwtHelp等的相应对象。

After getting aquanted with the above procedure, you might want to break up the code in many files using a design pattern as suggested by Andrei. 在完成上述过程之后,您可能希望使用Andrei建议的设计模式来分解许多文件中的代码。

Simply clear the root panel ( RootPanel.get().clear() ) and add the widget for your new "page", the same way you added your first one. 只需清除根面板( RootPanel.get().clear() )并为新“页面”添加小部件,就像添加第一RootPanel.get().clear()部件一样。

If you're using LayoutPanels, do RootLayoutPanel.get().clear() instead. 如果您正在使用LayoutPanels,请执行RootLayoutPanel.get().clear()

Look at Activities and Places design pattern: https://developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces 查看活动和地点设计模式: https//developers.google.com/web-toolkit/doc/latest/DevGuideMvpActivitiesAndPlaces

I highly recommend it for a multipage GWT app. 我强烈推荐它用于多页GWT应用程序。 It explains pretty well how you create different "views", that are driven by their "activities", and tied to specific "places" (pages) that users can navigate. 它很好地解释了如何创建不同的“视图”,这些视图由其“活动”驱动,并与用户可以导航的特定“位置”(页面)相关联。

Typically you use a LayoutPanel as your "page" container that occupies the entire available browser window. 通常,您使用LayoutPanel作为占用整个可用浏览器窗口的“页面”容器。 You split this LayoutPanel into 2-3 layers (zones), like top menu, side menu, main area. 您将此LayoutPanel拆分为2-3层(区域),如顶部菜单,侧面菜单,主区域。 Each area contains one widget, usually a ScrollPanel, FlowPanel, or HtmlPanel. 每个区域包含一个窗口小部件,通常是ScrollPanel,FlowPanel或HtmlPanel。 Then you use different widgets or HTML inside each of these widgets to display whatever you need. 然后在每个小部件中使用不同的小部件或HTML来显示您需要的任何内容。 You may also create your own composite widgets that you can reuse in different pages. 您还可以创建自己的复合窗口小部件,您可以在不同的页面中重用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM