Vaadin alternative for heavily loaded UI - gwt

Currently I am programming the Web Application based on Vaadin. I am quite happy with the learning cycle and the way how easy UI can be designed.
In general pluses of Vaadin are:
"Native" UI programming for Java users (component hierarchy / event listeners / drag & drop / validation).
Out-of-box nice collection of components (tree / table / list / ...).
The minuses are:
Big and complex HTML output. That slows down the browser response time (also mentioned here and there) and leads to some rendering peculiarities from browser to browser.
Difficulties in handling big number of components (see Can CustomLayout handle 5000 components?).
The need to recompile the widget set if you use 3rd party components.
My question to community is:
What Web Framework fits best the following requirements:
Separation of presentation with event/action handlers.
Common components out of box (with advanced features like table column drag&drop, lazy loading).
Layout support (no headache with padding and alignment of components).
Event propagation to server and server-side event processing.
Possibility to generate your HTML (if framework is not HTML-based) and also capture events for it (e.g. mouse clicks).
Possibility to register key stoke callbacks (e.g. Ctrl-S) is a plus.
Short learning curve for Java developer is a plus.
The sensible mix of approaches would fit as well. Please, provide the link for "Hello World" application, implemented based on the framework that you suggest. I am considering Apache Wicket / Echo2 / Tapestry / Click / GWT, but it's difficult to make a choice without playing for couple of months (hopefully with no deep disappointment).

I completely agree with all your mentioned minuses and can not say very much against. Because I'm quite new in GWT I can only share my little experience I have collected other last 2 months.
Separation of presentation with event/action handlers.
I think UiBinder with annotation #UiHandler("closeButton") #UiField in GWT 2.0 and later is exactly for separation HTML form code and handlers. Also MVP pattern with event bus is perfect answer from GWT team.
Short learning curve for Java developer is a plus.
I'm not naive and I don't think that it's possible to get quality result only with java knowledge without understanding WEB technologies.
Most of GWT UI frameworks I have reviewed and read about, introduces more problems than solutions. They somehow manages to and one or few benefits and restrict you from other features which comes in the new releases of GWT. I have chosen not to use vaadin because I felt like It will force me to do webapp development in their way, which I agree is fast easy to understand, but somehow limited. I like to have some freedom by choosing classic GWT without fancy controls.
Also I also feel that GWT UI Components are limited and there is no quality alternatives. Something is wrong here. I think google team have to do something on this part.
Regards RemisB

You can use a Vaadin Table to solve the original problem, more or less like this. The trick is to create a Vaadin Container and put components in it, as data. On the text side, wrap a label in VerticalLayout then add a click listener. This yields the ability to display "paragraphs" of XHTML text, detect clicks on them with relative locations, and still be able to handle large numbers of paragraphs.
You might need to modify your styles.css to allow wrapping of text within a table row, so you'll get ragged rows.
package com.soletta.clickytable;
import com.vaadin.Application;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.event.LayoutEvents.LayoutClickEvent;
import com.vaadin.event.LayoutEvents.LayoutClickListener;
import com.vaadin.terminal.Sizeable;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
import com.vaadin.ui.Window.CloseEvent;
import com.vaadin.ui.Window.CloseListener;
public class ClickytableApplication extends Application {
#Override
public void init() {
Window mainWindow = new Window("Clickytable 2 Application");
setMainWindow(mainWindow);
mainWindow.addListener(new CloseListener(){
public void windowClose(CloseEvent e) {
WebApplicationContext context = (WebApplicationContext) getContext();
context.getHttpSession().invalidate();
close();
}});
IndexedContainer container = new IndexedContainer();
container.addContainerProperty("text", VerticalLayout.class, new VerticalLayout());
container.addContainerProperty("edit", Button.class, new Button("Edit"));
for (int i = 0; i < 10; i++) {
final int index = i;
Object item = container.addItem();
Label lbl = new Label("Text Content " + i);
VerticalLayout vl = new VerticalLayout();
vl.setWidth(100, Sizeable.UNITS_PERCENTAGE);
vl.addComponent(lbl);
vl.addListener(new LayoutClickListener() {
public void layoutClick(LayoutClickEvent event) {
System.out.println(String.format("Clicked on text %,d at client(%,d,%,d), relative(%,d %,d)\n", index, event.getClientX(), event.getClientY(), event.getRelativeX(), event.getRelativeY()));
}
});
container.getItem(item).getItemProperty("text").setValue(vl);
container.getItem(item).getItemProperty("edit").setValue(new Button("Button " + i));
}
Table table = new Table("ClickyTable 2", container);
table.setColumnExpandRatio("text", 1);
table.setColumnExpandRatio("edit", 0);
table.setSizeFull();
VerticalLayout fl = new VerticalLayout();
fl.setSizeFull();
fl.addComponent(table);
mainWindow.setContent(fl);
}
}
With some style changes in place, the result can look something like this:
ClickTable Screen Shot http://www.soletta.com/images/ClickyTable.PNG

If you ever find yourself putting hundreds of components on web page in Vaadin, you probably should reconsider your application structure. Why not implement a custom widget for the part of the UI that requires such huge number of widgets? It is just GWT and thus fairly easy. Then you can have the best of the both worlds - simplicity of Vaadin with full control of HTML5 on the client side.

Vaadin Flow
You must have been using the previous generation of Vaadin, versions 6, 7, and 8.
Because of the limitations and incompatibilities of earlier browsers, the long delays in producing CSS 3, and predating HTML5, Vaadin did indeed generate large and complicated pages. Given the relatively poor performance of JavaScript runtimes back then, some elaborate web apps may not have performed as well as you would have liked.
Web Components versus GWT
Fast forward some years now since your Question was posted. Vaadin Flow has arrived. Versions 10 and later are longer based on GWT. Instead they use the open standards that have emerged, collectively known as Web Components.
CSS 3
CSS 3 has finally arrived, and matured. Browsers now offer built-in sophisticated page layout with Flexbox and Grid, in addition to the previous Float. So no longer must page layout be hacked together with abuse of table and crazy assortment of div & span tag soup. Page layout can now be built with short, simple, and clean code.
Modern browsers
Other modern advancements include:
HTML5 designed expressly for building web apps (as opposed to web documents)
The consolidation in browser engines (basically only 2 left standing: WebKit/Chromium & Quantum/Gecko)
Dramatic advances in the performance of JavaScript runtimes, plus important new features of JavaScript 6
Close cooperation between browser makers in writing and implementing web standards with much more consistent behaviors
The "evergreen" rapid-release model of modern browsers
All these taken together mean the burden on Vaadin to deliver high-quality consistent web-app experiences has been greatly decreased. You should see much shorter, simpler, and faster page code.
Give it a try.
For more discussion, see my Answer to the Question, Understanding Vaadin Flow / Vaadin 10.
The minuses are:
Big and complex HTML output. That slows down the browser response time (also mentioned here and there) and leads to some rendering peculiarities from browser to browser.
No longer big and complex, as discussed above, because of modern web technology improving so much.
Difficulties in handling big number of components (see Can CustomLayout handle 5000 components?).
Web Components is an open standard, composed of four specifications.
Many components have been built over the last several years, now available for you to use in your Vaadin Flow web apps.
Most of the UI widgets you knew in Vaadin 6/7/8 have been rebuilt as Web Components (see Comparison Matrix). This means these Vaadin components can be used in other web projects without the Vaadin Flow server-side Java binding.
You can easily wrap other non-Vaadin-specific components built on Web Components to be available to your in your Java code running on the server-side Vaadin Flow framework. See Integrating a Web Component. To get you started, here are a couple thousand to choose from.
You can create your own components.
The need to recompile the widget set if you use 3rd party components.
No more WidgetSet in Vaadin Flow, because there are no more GWT widgets. Supplanted by Web Components as discussed above.
What Web Framework fits best the following requirements:
Vaadin Flow ticks all the boxes you listed in your Question: event handlers, common components with advanced features, sophisticated page layout, user-events propagating from client to server (and the other direction via built-in Push technologies), keyboard shortcuts, and a short learning curve for Java programmers.
Furthermore, from the server-side you can now invoke JavaScript snippets on the browser. And Vaadin 15 this spring brings client-side coding in TypeScript while still integrating with the Java code running server-side in Vaadin Flow.

Web Firm Framework is the best alternative. It's an opensource Java framework under Apache License 2.0. I also had to load heavy components in my application it was smooth with this framework.
It is like a collection of java classes for all HTML5 tags and attributes. Using these classes we can build the UI just like we do using the pure HTML. It can handle heavy HTML because the data coming from the server to client is like a stream through websocket, eg:-
//creates table
Table tableObj = new Table(null,
new Style("width:100%")).give(table -> {
new TBody(table);
});
//finding tbody object in the table
TBody tBody = TagRepository.findOneTagAssignableToTag(TBody.class, tableObj);
for (int i = 0; i < 10; i++) {
int count = i;
Tr trObj = new Tr(null).give(tr -> {
new Th(tr).give(th -> {
new NoTag(th, "Firstname " + count);
});
new Th(tr).give(th1 -> {
new NoTag(th1, "Lastname " + count);
});
new Th(tr).give(th2 -> {
new NoTag(th2, "Age " + count);
});
});
//appending tr in the table
tBody.appendChild(trObj);
}
Whenever trObj is appended it will be immediately available in the UI it will not wait to finish the for loop. Check their demo app which contains a button to stream 1000 rows.
We can handle events without much effort eg:
to handle click event of a button
//This will create a button in the UI.
new Button(null, new Type(Type.BUTTON), new OnClick((data, ev) -> {
System.out.println("Button clicked");
return null;
}));
In this git repo you can find sample projects for it.
We can also try this tool to convert HTML5 to Java/Kotlin code. This video and developers guide will be helpful to understand it better.

Related

How to achieve Two Way data binding in native GWT?

We have been using GWT for around 4 years now. One of the most often discussed features missing in native GWT is data binding. Reading across AngularJs another Google offering, i came across http://devgirl.org/2013/03/21/fun-with-angularjs/ . I do not wish to use GXT or any other third party tools. I also wish to avoid generator related solution.
Is there any way this will ever be implementable in pure native GWT?
Is there any specific reason why GWT cannot provide this out of the BOX?
Have you tried GWT Pectin?
I have used it successfully in a larger project some time ago.
I suggest you try HexaBinding, which is non invasive and only focused on data binding. Here is the link : https://github.com/ltearno/hexa.tools/blob/master/hexa.binding/README.md
It works with pure Java, GWT and will soon work also with Android and JavaFX. It may even work with J2Objc but not sure yet...
I read the post you mention on devgirl about AngularJS. In that post the "2 way data binding" refers to the property of the code to reflect automatically on the view the changes that occurs to the data that the view is currently displaying.
This is achieved in GWT since version 2.1 with the Cell Widgets
In the first paragraph of the Cell Widgets documentation I linked above it is clearly stated that:
A cell widget can accept data from any type of data source. The data
model handles asynchronous updates as well as push updates. When you
change the data, the view is automatically updated.
If you want to do in GWT something as basic as the example in the devGirl post you need to write a onKeyup handler (in AngularJS you should write a Scope to this purpose) that would copy what you entered to the linked label. Something like this:
...
final TextBox nameField = new TextBox();
final Label enteredName = new Label("");
...
public void onKeyUp(KeyUpEvent event) {
enteredName.setText(nameField.getText());
}
...

Creating a responsive design using CQ5 templates

I'm investigating Adobe CQ5 and would like any advice on how to integrate its drag-and-drop UI to create a responsive website. It seems as if it works on a concept of fairly bland templates with components that can be dropped in pretty much anywhere, including things like "three-column control" - which would make designing a responsive grid structure very hard (as it would be hard to prevent users from dropping in a control that could ruin the layout).
Does anyone have any experience or advice on this? I'm really looking for deep technical details on the structure of templates vs components (paragraphs), and where/how to manage to the CSS.
CQ5 offers ways to control what can be done within a template, so thinking that components "can be dropped in pretty much anywhere" may be misleading. Page templates are designed and configured so that you control which components can be added to a certain area of a page. This allows you to only make those components available that will work with the template layout, excluding components that would wreck the layout. Then authors are only allowed to use things that will work. If they attempt to drag a component onto a paragraph (parsys) where that component has not been configured as available, the UI will not allow them to use it there. So CQ actually makes it easy to prevent users from dropping a control somewhere that would ruin the layout.
This is outlined a bit here:
http://dev.day.com/docs/en/cq/current/howto/components_develop.html#Adding%20a%20new%20component%20to%20the%20paragraph%20system%20%28design%20%20%20%20%20mode%29 which states that
"The components can be activated (or deactivated) to determine which
are offered to the author when editing a page."
When it comes to CSS and JavaScript, you can create a client library and then include the relevant client library on the page. Backend CQ functionality will take care of combining multiple CSS (or JavaScript) files into a single minified file to allow for a single HTTP request of an optimized file. This it outlined a bit here:
http://dev.day.com/docs/en/cq/current/developing/widgets.html#Including%20the%20Client-Sided%20Code%20in%20a%20Page as well as
http://dev.day.com/docs/en/cq/current/howto/taglib.html#%3Ccq:includeClientLib%3E
So you might develop several components that share a client library, then when any of the components is added to a paragraph the client library will be included on the page. You may also want a CSS library that applies to all the templates to give a common look and feel, yet allow components to add their own when they are used.
These guidelines for using templates and components outline how you provide control, yet flexibility:
http://dev.day.com/docs/en/cq/5-5/developing/developing_guidelines_bestpractices.html#Guidelines%20for%20Using%20Templates%20and%20Components
I'll document our successful WIP experience with RWD and CQ5
Assumptions:
A well documented style guide.
Our First Steps:
Modified existing column control component css to utilize twitter bootstrap grid css.
Create a base page property allowing two different classes on the grid container to be set and inherited by child pages. (container||container-fluid).
Leverage out-of-the-box components where ever possible.
All component widths inherit the width of their parent container allowing for components to be dropped into any location within a template.
Issues:
The out-of-the-box column control component can not be nested.
We are looking into building a custom column control component.
Takeaways: this is an evolutionary project and we are constantly iterating.
With the recent launch of AEM 6.0, they have an example website called as Geomatrixx Media. This website is responsive.
You can take this example as reference and start building on top of it.

gwt; mixing html pages with java code

I really like the approach in GWT where you can define "divs", "spans" etc in a regular html page, then in the GWT entry point simply push a button or some other component inside the div.
So small example, here is a snippet of a gwt html page:
<body class='page'>
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position: absolute; width: 0; height: 0; border: 0"></iframe>
<div>
Query Terms: <span id="txtQuery"></span>
<span id="btnQuery"></span><br>
...
</div>
</body>
And here is a small java snippet contained in the gwt entry point:
ClickHandler clickHandler = ...
TextBox txtQuery = new TextBox();
Button btnQuery = new Button("Query", clickHandler);
RootPanel.get("txtQuery").add(txtQuery);
RootPanel.get("btnQuery").add(btnQuery);
One of the reasons I like this approach is that it allows non java coders to design / write the html stuff, and I also like the separation between GWT / java code and the html code.
However... this may work well for a simple web page, but how do you scale this approach up into many webpages? From what I understand, the "GWT way" of doing things is to have one webpage and use history to hide and show various GWT components. I have built 2 projects in GWT using this standard technique, but recently discovered that you can do the sort of thing I showed above.
Is there any way of scaling the above 2 snippets into multiple html pages, where GWT injects its components into standard html pages?
here is no GWT way. At least not in GWT mission statement. If you want to pursue your aproach there are multiple ways how you can do it.
GWT app per page. (e.g. on each page a gwt app specific for this page is included). You simply compile a new GWT module for each page where you need some GWT functionality. You can use few of them together on one page, or none. This approach is good if you GWT apps are going to be really simple, and you don't need to use stuff like GXT Grid on every single page with different settings, otherwise you will waste user browser will have to download large chunks of JS code over and over, and this will be a big problem if you have a lot of pages.
One big GWT app for all pages. Just put everything into single GWT app, create some kind of switch (some js variable) so the app knows what it has to create. Some code splitting might be used, so on each page only things which are really required will be downloaded. Since the same JS will be used on each page, caching should solve the problem with downloading application code over and over (but you still have the problem with actually parsing/running the code very time user changes the page)
There is also a third approach, the most effective of all, but the hardest as well. As soon as the user loads one of the pages, there is no more navigation, gwt module simply takes template for page to which user wants to navigate, and replaces current html code with newly generated template. This is quite easy to achieve, if you will use TextResource from ClientBundle and HTMLPanel. The problem is with navigation in address field (GWT app will have to be responsible for changing the address, so the users can create bookmarks or send the link to their friends). You will use one single GWT script for this and some code splitting is recommended.
All three approaches are totally valid, depending on your requirements you can pick any of them. Also if all you want is to provide people ability to use HTML to layout GWT screens, you might want consider using combination of HtmlPanel and ClientBundle's TextResource.
If the goal is to have designers work on HTML rather than Java, then how about UiBinder? It'd give you what you want (separate HTML –or rather, XHTML-like– code from Java code) inside a GWT project.

Best practices for designing GUI in GWT

I have recently started studying Google Web Toolkit. I have went through some walkthroughs, and I think I understand the basics and the idea. However, I have some questions on the overall architecture and design of the applications.
Let's start with the GUI. I want to build a "common" web application, where the user first sees a login page. After successful login, the user is redirected to some kind of index page and a menu is added. I created a new LoginComposite for the login page, and tried to design a nice looking HTML table using the GWT Designer. However, I find that really hard to do, as you cannot set any individual properties on the individual cells (TDs)? There's no way to specify colspan or rowspan, and I can't set any padding or margin on the cells themselves. In short, I know exactly how I would have written the HTML code, but I can't translate that to the designer. Is that just me?
Also, I am wondering about the best practice for code layout and design. I went through the StockWatcher tutorial, but that's really not a very realistic web application. For example, I would like to know how I should design different forms (should each be in a own class inheriting the Composite-class)? How should I switch between forms (for example, first a list view, then a form for editing a chosen item from the list, then a totally different page)? If I have one Composite for each page, and instantiate them when needed in my EntryPoint, would that mean that the client will download all the JavaScript for all those Composites at page load? Should I stick with only one HTML page, or should I have many?
These are questions not really covered by any GWT tutorial. If anyone know a good example of a "real" web application built using GWT, I would love to see it.
Thanks for your input!
There are a whole bunch of resources in Google IO talks. For example:
http://www.google.com/events/io/2011/sessions/high-performance-gwt-best-practices-for-writing-smaller-faster-apps.html
http://www.google.com/events/io/2011/sessions/highly-productive-gwt-rapid-development-with-app-engine-objectify-requestfactory-and-gwt-platform.html
http://www.google.com/events/io/2010/sessions/architecting-production-gwt.html
http://www.google.com/events/io/2010/sessions/architecting-performance-gwt.html
http://www.google.com/events/io/2010/sessions/gwt-ui-overhaul.html
http://www.google.com/events/io/2009/sessions/EffectiveGwt.html
Also, don't expect to be able to edit absolutely everything if you are using the GUI to build your GWT app. Good luck!

Paging a GWT-EXT datagrid with GWT-RPC?

I need to display data coming from a GWT-RPC service in a paginated datagrid.
The gwt-ext showcase does not provide an example combining gwt-rpc calls and datagrids.
That is too bad because the original javascript Ext grid components offer paging and remote sorting. How to take advantage of these features with GWT ?
I too wanted to do this a few weeks ago, and searched long and hard and found nothing. In the end I wrote my own paged grid that supports RPC/Sorting/Editing/Etc.
It's intended to be generic, and is still a work in progress, but to use it you simply implement the TableSource and TableRenderer interfaces like so:
new PagedTable(new AssetTableSource(), new AssetTableRenderer(), 30);
I have posted the code here:
http://wiki.shiftyjelly.com/index.php/GWT#GWT_RPC_Paged_Table
Feel free to revert the buttons in the PagingControl.java back to normal GWT buttons.