1

I am developing a web app with GWT. I'd strongly prefer to code everything in Java instead of hardcoding anything in HTML and CSS. I'm also using GQuery (or GWTQuery) and I'm wondering if using compile time selectors with GWTQuery completely eliminate the need to hardcode any HTML or CSS at all - and have the speed and performance of a fully hardcoded app?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
EternallyCurious
  • 2,345
  • 7
  • 47
  • 78
  • What do you mean by 'fully hardcoded'? Do you mean as if it were static html/css with zero JavaScript? In that case, no, since the GWT app will compile to JavaScript, which has to be run at some point. The purpose of those compile time selectors is to let the build process optimize the queries as much as possible ahead of time - they still need to be run though. – Colin Alworth Apr 13 '13 at 16:17
  • By "fully hardcoded" I mean, written in HTML/CSS and Javascript in the traditional way, instead of being compiled into from Java or another language. To simplify, I mean to ask, whether compile time selectors would be compiled into Javascript that writes to HTML and CSS OR directly into HTML and CSS. – EternallyCurious Apr 14 '13 at 04:58
  • Like @Manolo said (and I think I said above), GWT turns Java into JavaScript, and includes some html and css along for the ride. It does *not* generate a single static html/css file that the browser simply renders - if your code is simple enough to be expressed as static content, then JavaScript wouldn't even enter the picture. No, GWT does not generate finished html files without JavaScript, any more than a C compiler would generate a "Hello World" static file when all that the `main()` does is to printf that string. The program and the output are not the same. – Colin Alworth Apr 14 '13 at 20:45

1 Answers1

1

Let me explain with few words what gwt and gquery are.

1- GWT is just a compiler which gives you the tools to produce optimized javascript from java.

2- The js produced with GWT is mainly used to modify the DOM (apart from calculations, business code, ajax etc).

3- GWT additionally gives you a set of widgets, as an abstraction of the DOM, so as you can work with panels, buttons, trees, etc. instead of raw HTML. I think this is what you call hardcoded html.

4- But GQuery is a complement to GWT. It gives you a set of utilities taken from jQuery and ported to java to write less code, it is mainly oriented to manipulate the DOM (select nodes, modify, animate, etc) apart from other cool features like an easier ajax syntax, safe typing, promises, json/xml data-binding, etc.

Said that, don't think that the gwt widget abstraction will make you completely forget about dom and css. Sooner that later you will need to create your own widgets, or customize the current ones.

I think that the only way to forgot almost the DOM is to use a 3rd party widget library like gxt, mosaic, smart-gwt, etc. Because the GWT widgets are tough, they are designed to give the designer the option of easy stylizing them with css.

In the other hand, gwtquery will not help you to forget the DOM at all. It is designed to enhance static DOM elements which are in the page, enhance the DOM of gwt widgets, or create your own DOM structure based on html.

About gQuery compiled selectors, they are used in the same way dynamic selectors are: to select DOM elements, but with a much better performance because the compiler optimizes them. I think you misunderstood their objective, they don't give you any way to eliminate hardcode HTML.

UPDATE: To answer your last comment, it is NOT possible to generate static HTML or CSS with GWT or GQUERY. They always produce static JAVASCRIPT code written to .js files (or written into javascript tags in .html files depending on the linker)

Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27
  • I was assuming that compile time selectors produce CSS and HTML, when the GWT project is compiled INSTEAD OF producing javascript that writes to CSS and HTML at run time. If this assumption is right, it should be possible to maybe just put a couple of
    elements in the HTML and then write everything else to them with compile time selectors - but still have the performance of an APP where the HTML and CSS were traditionally hardcoded.
    – EternallyCurious Apr 14 '13 at 04:29
  • Being a Java developer, I'm somewhat dependent on the kind of type safety that coding separately in HTML, CSS and javascript does not offer - so I'm looking to work around that with GWT and GQuery without compromising runtime performance. AND I'm building all my widgets from scratch, to maintain a unique look. – EternallyCurious Apr 14 '13 at 04:30
  • To simplify further - Is there a way in GWT (and GWTQuery) to have Java compile into HTML and CSS instead of Javascript? – EternallyCurious Apr 14 '13 at 05:27
  • The answer is no. Updated my response. – Manolo Carrasco Moñino Apr 14 '13 at 06:45