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 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).
Related
Is it possible to add GWT as a component in an already existing webpage?
I don't know what exactly do you mean by component, but GWT can be integrated in any web page,since GWT output is (mostly) javascript. JavaScript can be used in any page. It doesn't matter if the page is existing or you are just planning to create it. If you can include js on that page, you can use GWT.
Perhaps this is what you are looking for ?
Running a GWT application (including Applets) inside an IFRAME from an ASP.NET 3.5 app?
I think the answer on that question is relevant.
Yes, GWT can be added to any existing webpage.
GWT's RootPanel will be the div you place on that webpage.
Hope this helps.
You need to understand the constraints of browser technology. Perhaps, you already do.
To, answer your question, you have to return back to ground zero - javascript.
Are you able to write a simple javascript object that runs as a "component" of your current app, such that there could exists a duplex communication between your simple javascript object and the canvas of your current app? Can your simple javascript object invoke and be invoked by features of your current app?
Knowing that GWT ultimately gets compiled to javascript, and if even a simple javacript object cannot function componentially with your current app, would you think there is any hope to componentize a GWT app with your current app?
Setting up a communication channel
Componentization would require ability to communicate.
Let us say, you need to write your combo app using both jquery and GWT. Your jquery side should be able to dedicate a HTML element into which it could write. Like a simple DIV, ensuring that the element has an ID. You could have several elements for such a purpose.
On the GWT side, your GWT code would be able to grab these elements thro getElementById. Voila! There are your communication channels.
GWT is a dominating possessive creature, for one reason - it refuses to create widgets thro which you could name with an ID (except for ensuredebugId). For that reason, it does not fare very well running as a component.
More likely, your GWT app is the master and your non-GWT apps are the component.
It is a very "well-practiced field" of having non-GWT apps running as components to a GWT app. We have charting, chat, clocks, widgets, etc components written in jquery, javascript and even server-side services. And then we write GWT wrappers around their elements and use JSNI to communicate with them.
All these non-GWT avenues of creating DOM elements and javascript objects have the common ability to generate elements that can have an Id, which makes them more susceptible to be componentized under GWT than the other way around.
Good examples are the Javascript APIs for Google Maps, Google Location API. e.g. HighCharts http://www.highcharts.com/.
All you need to do is to create a div in your existing web-page and give it an Id.
Then use the following to insert your component into that div.
RootPanel.get("PUT THE DIV ID HERE").setWidget(superCoolGwtComponent);
Simple :D
Currently i am developing a CRM web applications using J2EE . For this application i need to support the localization for the layout such as menu names.
At the same time i need to allow admin to customize the layout such as adding new menu or deleting the menu and changing themes. I am planned to use XML for the layout specifications
Anyother methods to achieve this one?
Please help me .
Thanks in advance
Dilip
I think that If you use an XML you have to write your Parsers to read/write the settings updated by the users which will be time consuming and may be complicated.
I would suggest to use Database and put these Menus in master tables. Then you can create a table (for many to many relationship with menus and users) which contains the settings updated by the user. At the login or before generating the menus, you can get the menus specific to that user and display it as per your requirement. You can do the same for Themes.
I think, this would be bit easier and readable too.
What you want is Customization / Personalization, not Localization. Customization / Personalization involves a lot of work. There are special frameworks such as Oracle's WebCenter Framework that are proficient at this. If you get into writing this customization framework yourself, you will be developing and maintaining a lot of plumbing which will take time away from implementing real business functionality. I suggest that you do not re-invent the wheel and try to re-use an out of the box framework.
I have a Spring-MVC based webapp with a JSP front end. It is your basic CRUD app with various other management and reporting screens thrown in.
We are currently using JSP with JSTL for our view, but our designer doesn't know JSP so it's been a real pain to merge his design changes into the source. Due to that, my recent thought has been that if we could just hand the entire UI over to him and let him implement it entirely in HTML/Javascript, making ajax requests for JSON data for the dynamic portions, we would be able to remove that entire merge process and just host his static HTML files. Development for him would be simple as he would be able to hit our REST webapp on our test server for sample JSON data using jsonp.
If the designer is proficient with javascript, what would we lose by changing our spring-mvc webapp to only return JSON views and use jQote or jquery-tmpl to do all dynamic bits in the HTML?
Are there any deal breakers in going this route?
You'd just lose the ability to take advantage of JSP-based frameworks and templates. If:
your developer is proficient in Javascript,
you expect future developers in his place to be proficient as well, and
you are okay with making javascript a requirement for your site
then this can be a good strategy. The JSON will probably make your AJAX calls a lot faster than returning actual content would do. You'll probably be able to make the site a lot more responsive to user interaction.
The problem with injecting content via JavaScript is that search engines cannot see it. They get the page source as it is a load time. If this is an internal application that may not matter, but if it's a public-facing site it could mean very bad things.
You can build entire interfaces from JSON data and a bit of JavaScript on the client. As a technique it works quite well and is fast, but beware of the SEO implications.
One more point to add:
Say you are loading 300 rows of data to show, then you will have to load 100 row using JS and then show it to user.
It will mimic the streaming features. Content will be shown after request is populated.
I'm working on a project, that requires forms on page to be divided and put into separate tabs. Apache Wicket have very nice and simple way to do tabs by itself (TabbedPanel class), but my concern is, that this solution rely on AJAX for loading the content of the panels, hence the only one part of the form would be submitted after user presses "Submit" button.
I found a solution for simple CSS/JS tabs (http://www.barelyfitz.com/projects/tabber/), but I feel uneasy to use third party solution, and it is complicating my project (also, I'm not sure about the license).
What should I do?
There are several impls of TabbedPanel with JQuery which are completely JS/CSS based.
See wicketstuff's jquery integration project and WiQuery project.
The default TabbedPanel doesn't use AJAX. To use Ajax there is a own implementation (AjaxTabbedPanel).
This sounds very much like a wizard to me. Since wicket provides a wizard component to handle this kind of use case this might be a good point to look. Since I've not yet used this component I don't know how far it can be taken to display tabs but if it can't, it might at least give you the idea on how to build your own with tabs.
I'm making a game in java. Is there any way I can create HTML widgets for use in the game as the UI? It'd be great if I could attach some event handlers to the controls and fully use CSS, too.
You can use HTML and CSS for your game, but you'll need a servlet to handle requests.
Event handlers may be written in JavaScript, but they'll ultimately have to communicate with a server on the back end.
I know that this doesn't really anwer your question, but there is a library called Amino, that allowes you to use CSS to skin GUI components. That might grant you at least part of your wish.
"If there is a will there is a way"
If you're using raw Java instead of a framework that might give you some ready-made widgets, I believe you'll have to handle the HTML rendering yourself.
In Swing, one would look up class javax.swing.text.html.HTMLEditorKit for understanding how Java's JEditorPane renders basic HTML + CSS (the inner class HTMLFactory is particularly interesting as it creates the views that will render each HTML element). Perhaps this won't help you much, but maybe this would be a starting point.
Stanislav Lapitsky has done of a lot of work in Swing-HTML and gives tools that help you understand how to deal with HTML rendering. Check it out:
http://java-sl.com/about_author.html