Hjem   |   Kontakt   |   Sitemap
Hvem er vi Hvad kan vi Vores kunder Ledige stillinger Kontakt os Blog

Posts Tagged ‘AJAX’

Dependent dropdowns in Grails

Published Friday, September 18th, 2009 by AN

It does really seem to be a very common problem with the dependend or chained drop-downs. At least it was one of the first problems I faced in the Grails app I’m working on now.

The solution is not really more or less elegant than the one for Seam and Richfaces. I followed the guide on Grails.org but decided to make the solution a bit more general. So I pass the name of the select-element-to-update as a string to the update function. This way I can also put the function in a separate file for inclusion (updateselect.js).

function updateSelect(e, elemId) {
// The response comes back as a bunch-o-JSON
var values = eval("(" + e.responseText + ")") // evaluate JSON

if (values) {
updateSelectFromJSON(values, elemId);
}
}

function updateSelectFromJSON(values, elemId) {
var rselect = document.getElementById(elemId)
// 	Clear all previous options
rselect.options.length = 0

// Rebuild the select
for (var i=0; i < values.length; i++) {
var opt = document.createElement('option');
opt.text = values[i].name
opt.value = values[i].id
try {
rselect.add(opt, null) // standards compliant; doesn't work in IE
} catch(ex) {
rselect.add(opt) // IE only
}
}
}

Which is then called like this


...

<form>
optionKey="id" optionValue="name" name="country.name" id="country.name" from="${Country.list()}"
onchange="${remoteFunction(
controller:'country',
action:'ajaxGetCities',
params:''id=' + escape(this.value)',
onComplete:'''updateSelect(e, 'city')''')}"
>

</form>

One thing is missing from this solution, though. Unlike the solution on grails.org, the chained select is not updated based on the default value of the previous select. This can be fixed by inserting the following in the head element of the .gsp page.


function init() {
document.cityform['country.name'].onchange();
}
window.onload = init;

Groovy web shells – ajaxgroovyshell

Published Tuesday, May 19th, 2009 by AN

For the JEE web-app I am currently working on the main audience is power users/admins. So while I can code some usecases as nice seam pages that help the user solve a task, other usecase are difficult. The most difficult are the general batch processes that take the form “select, filter, apply”.

Unix users (who use shell scripts) know that a small amount of programming is effective at solving these problems. So for my web-app I was contemplating how to get something “shell-like” into the project. There are several projects that present a nice AJAX based web interface to the system shell on unix machines. Eg. shellinabox and ajaxterm. And there are several programming languages that seem suited for interacting with a Java app. Eg. Groovy, Jython, or Beanshell.

So I decided to try to combine the interactive groovy shell with an ajax frontend. After looking around quite a lot I found shellinabox which has a nice GPL’ed javascript vt100 front end (I found another here which is LGPL’ed).

After a some weekend studies of shellinabox I could make a prototype with the vt100.js of shellabox and the nice little python webserver of ajaxterm. With a little more hacking I was able to hook up the groovyshell as a web-app through a java servlet. The interactive performance sucked, because of some weirdness in standard java.io.PipedInput/OutputStream classes, but fortunately I was not the first with that problem so with some small hacks to the replacement classes from LiveGraph the interactivity became tolerable.

From this working state there is actually still quite a bit of work to have something that I can deploy on a customer production server. But when Guillaume Laforge announced his cool little app “GroovyWebConsole” to run a groovyshell on the Google AppEngine I figured that I might as well upload what I had and announce it as well. Here is the announcement I sent to groovy-users

I have made a similar app to administer a JEE app I’m doing. It is
similar but is stateful and uses a vt100 interpreter in javascript (from
shellinabox).

You can find it here

http://code.google.com/p/ajaxgroovyshell

It is mostly a prototype – to be really useful for me I need to add

1) Access control
2) A way to paste text from the system (a pop-up textarea?)
3) Proper sessions
4) A robust way to handle threads
5) Syntax highlighting?
6) Better tab completion in GroovyShell (more like ipython)
Unfortunately it won’t run on the Google AppServer since I need a thread
for the GroovyShell.

Best
Anders

Since then I have noticed several java server projects that have some kind of console facility. But not as an ajax webpage (yet). I have suggested it a couple of places (like for Hudson, and for FRESH).


Creating, consuming and testing SOAP webservices on Grails

Friday, February 12th, 2010
We are currently making a backend system, that has its services exposed as webservices. Since ...

My first patch to Grails accepted

Monday, November 23rd, 2009
I recently wrote a patch for Grails to support dateCreated and lastUpdated when using mockDomain ...
 
© 2008 Code3 ApS  |  Rådmandsgade 45A, 1.  |  2200 København N  |  +45 7020 3383  |  kontakt@code3.dk