开发者

Achieving multipage GWT website

开发者 https://www.devze.com 2022-12-11 20:32 出处:网络
I have a question on managing a multipage GWT website. For now I only have one html page in which I embed lots of divs to store the widgets that I use. Then, according to the user\'s actions I add or

I have a question on managing a multipage GWT website. For now I only have one html page in which I embed lots of divs to store the widgets that I use. Then, according to the user's actions I add or remove the necessary divs using GWTs DOM class. Therefore, I use only one html page to simulate multiple pages. Is there a better way to do 开发者_JAVA百科this?

Thanks.


I disagree with cletus. In my experience, gwt is just as good at enhancing multipage apps as it is at one-page applications like gmail. It just depends on what you're requirements are for your web app.

I'd agree that writing one-page applications is definitely the place to start, but once you get the concept of gwt modules, they can easily be used to add custom javascript to multiple pages.

To answer your question; I think your design of using one page and swapping out widgets is perfectly acceptable.

These talks might help to give you ideas about when multi page apps might make sense:

  • Effective GWT: Developing a complex, high-performance app with Google Web Toolkit

  • Progressively Enhance AJAX Applications with Google Web Toolkit and GQuery


GWT is designed primarily for one-page applications. There is good reason for this. You take a hit every time you do a page transition with so much Javascript. The page load times are so noticeable. Think of goign to GMail. You have a period of 1-5 seconds where it loads. Now how would your user experience be if that happened whenever the user went to a new page and that happened a lot?

Neither do you need to put every widget on the page. You can dynamically create and add (or remove) widgets as you see fit. It's a somewhat different approach to how you'd normally do a traditional multi-page HTML-centric Website.


Something I have found useful is using the GWT DeckPanel. A deck panel is like a deck of cards where each "card" is a GWT Panel. You can treat these "card" panels like pages and initialise and populate them with widgets at startup. You can then respond to user navigation actions by bringing a "card" panel to the front of the deck so that the user can see it.

The sort of approach works best as part of either the MVC (model-view-controller) or MVP (model-view-presenter) design pattern.


In order to achieve such a thing, you should have history management - like Gmail, which can use back/forward. It is achieved by anchors, and this class


In addition to the good DeckPanel and History suggestions, I'd also add that you can get GWT to split your app into multiple JS files that are dynamically loaded as needed with runAsync. This let's you have a very fast initial page load and load the new "pages" as the user needs them.

LazyPanel.createWidget() is a convenient place to stick a runAsync call that can be combined with DeckPanel or TabPanel to dynamically load content and UI code. A controller/presenter for navigation is even better (though a little more work on the programmer sometimes).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号