Saturday, August 2, 2008

Simple GWT Spring Webapp Example

I finally had time to finish up the GWT example I've been working on. I may add a bit more to it in the future (like an autocomplete search widget), but there is a lot there and should be helpful getting people started integrating GWT with Spring.
My general impression of using GWT is positive. It's definitely nice that you can work in Java and all the JavaScript is generated for you. Especially that it should perform well and work in different browers. It's a little tedious keeping everything in sync between the static servlet I use when running GWT in debug mode (avoids integrating Spring and injection into GWT debug) and the Spring controller. Also to have GWT use the main message resource for internationalization, a JavaScript object has to be maintained on the static HTML and JSP page (GWT debug vs. Spring webapp). It also wasn't obvious that if I made a bean to use with the main GWT entry point class that it had to be in the same package or a subpackage.

Also, as a side note, I have the person form working using Spring JS. It isn't too much work once I realized that it was working, but Spring Web Flow was refreshing the page afterword until I added at the end of the 'save' transition a render element specifying to only update the 'content' fragment. Otherwise only the 'onclick' attribute of the save button has to be modified.


<input type="submit" id="save"
       name="_eventId_save" value="<fmt:message key="button.save">"
       onclick="Spring.remoting.submitForm('save', 'person', {fragments:'content'}); return false;"/>


You currently can't specify a target div for returned fragments. I filed a JIRA (Enhance AjaxEventDecoration in Spring JS to specify a Target Div) to allow a targetId. Ideally it will be a list like fragments so you can specify what fragment goes with what div. I wanted to be able to have menu links refresh the content div without refreshing the entire page. Current funtionally assumes that you would just use AJAX for updates within functional areas. Like, I'm on the person page and want to just update the messages and personForm divs with fragments. So the fragment is expected to be wrapped in the div that is already is on the page and they are automatically matched up and updated. I think it will be a useful feature and hopefully will get added in an upcoming release.

No comments: