Saturday, February 25, 2006
Alternative to implementing js as jsp
Here is an idea that is not as simple as just directly implementing js as jsp, but is probably more performant and maintainable: for each js, we also have a corresponding jsp. For example
Foo.js
Foo.js.jsp
Within Foo.js, it's pure static javascript, but optionally with "hook"'s that the Foo.js.jsp can fill in during runtime on the enclosing page. For example:
Now all the *.js can be pushed to the Web server front end (eg Apache) - solves the performance issue. All the dynamic content is maintained in one single place: the respective jsp connected via a javascript class - solves the maintenance nightmare issue.
Foo.js
Foo.js.jsp
Within Foo.js, it's pure static javascript, but optionally with "hook"'s that the Foo.js.jsp can fill in during runtime on the enclosing page. For example:
This way, all the dynamic content are included as Javascript class level variables in the main page, and the static Foo.js just refers to these variables.
Foo.js
------
// Constructor of the Javascript Foo class.
function Foo() {}
...
// Anytime it needs to access a dynamic property that needs
// to be determined by the Java App, or tag lib, or whatever,
// use a class level variable.
// For example, a i18n message to be displayed.
alert(Foo.FOO_MESSAGE);
...
Foo.js.jsp
----------
// Foo.js.jsp is included in the main page where the reference to Foo.js is made.
// If there is no dynamic content, Foo.js.jsp just evaluates to do nothing.
Foo.FOO_MESSAGE = "<c:out name="${fooMessage}" />"
Now all the *.js can be pushed to the Web server front end (eg Apache) - solves the performance issue. All the dynamic content is maintained in one single place: the respective jsp connected via a javascript class - solves the maintenance nightmare issue.
Monday, February 06, 2006
Replace tabs with spaces
# Replace tabs with 4 spaces in all java files
for i in `find . -name '*.java'`; do sed -ie 's/\t/ /g' $i; done
# Clean up left-over
find . -name '*.javae' -exec rm -f {} \;
Wednesday, February 01, 2006
Eclipse WTP rocks!
The Eclipse Web Tools Platform Plugin Project is awesome! Great for developing J2EE applications. I particularly like the visual schema editors for xsd and wsdl files.
Can be easily installed via the Eclipse Update Manager by entering this URL:
Can be easily installed via the Eclipse Update Manager by entering this URL:
Works like a charm with Eclipse 3.1.2.http://download.eclipse.org/webtools/updates/