Is there a way to create GWT Widgets using JavaScript (with less effort)…for example like the one below?
Since GWT compiles to JavaScript, this should be possible, has anybody attempted this earlier… I love GWT widgets and JavaScripting, but not Java 🙂
function doSomething(){
layout = new FlexTable();
layout.spacing = 6;
cellFormatter = layout.getFlexCellFormatter();
// Add a title to the form
layout.setHTML(0, 0, 'form title');
cellFormatter.setColSpan(0, 0, 2);
cellFormatter.setHorizontalAlignment(0, 0, HasHorizontalAlignment.ALIGN_CENTER);
//......
// Wrap the content in a DecoratorPanel
decPanel = new DecoratorPanel();
decPanel.setWidget(layout);
}
You can use native javascript which can be called from within your Java code.
You can then call this like any other java method, caling this in an
AttachHandlerwould allow you to call this once the widget it is within is attached to the dom.That said, the whole reason to use GWT is that you end up writing both client and server side code in Java, the client side is cross compiled to very efficient cross browser javascript.
I would learn Java properly and continue to use Java code for the bulk of your GWT application, but use javascript native methods where they are needed, i.e. for doing stuff that GWT cannot do.
An example, I have some annotation code ive written in jQuery whcih I can not do in straight GWT. I have written some native methods that allow me to interact with the javascript code ive written. You can also pass and return values to and from javascript.