View Single Post
Old 11-08-2012, 06:10 PM   #8
photon
The new goggles also do nothing.
 
photon's Avatar
 
Join Date: Oct 2001
Location: Calgary
Exp:
Default

Yeah it looks off because the onchange string is something else, either Groovy, or something for the Grails framework to replace anyway. That's why it's got the crazy apostrophe escaping, it's going in and out of the scope of the framework language and javascript inside the markup. It's not a javascript function, it's a call to create a javascript function.

When I render the page I actually get this in the final page:

Code:
onclick="jQuery.ajax({
type:'POST',
data:'obj.id=' + document.getElementById('ele').value + '&obj2.id=' + document.getElementById('ele2').value +'&id=' + 2, 
url:'/url/to/anAction',
success:function(data,textStatus){jQuery('#targetDiv').html(data);},
error:function(XMLHttpRequest,textStatus,errorThrown){}
});"
It is kinda cool because I don't have to worry about paths or anything, it just wires everything up for me. The "2" in there is actually from a domain object.

I'll try the jquery thing to get the element value, though I have to be careful since the framework is kind of intended to be javascript framework agnostic (i.e. I change one thing and it'll use prototype everywhere instead). There might be a better way to access that value that leverages that, but I'm still a web n00b with Groovy/Grails, everything I've done so far is 100% back end stuff.

EDIT: Funny you say that about Javascript, I'm an old stuffy developer who holds onto his strongly typed languages with a death grip, I use Groovy a lot now which is kinda like Javascript in how dynamic it can be (just def varName and away I go, or add a property if I need it when I need it), but since it's Java underneath I usually still like to do List<DomainObject> list rather than def list. And in the roadmap for Groovy going forward they're talking about more strong typing!

I guess I just use as much of the syntactic sugar as I like and really like the convention over configuration vs. 1 million XML files of Struts or Spring, but I still like the comfort of strong types and the compiler / IDE support that that can bring.

I don't mind Javascript so much I guess, it's more browsers I hate.
__________________
Uncertainty is an uncomfortable position.
But certainty is an absurd one.
photon is offline   Reply With Quote