|
Hey,
Am fairly new to Grails, and am stuck on an issue in my first grails app (an exploratory contacts app). I have the following in my list.gsp : <g:select name="searchfield" onchange="alert(this.value);${session.sfs=this.value};" from="${['Firstname', 'Lastname', 'Country', 'Organisation', 'Region']}" keys="${['Firstname', 'Lastname', 'Country', 'Organisation', 'Region']}" noSelection="['':'--Choose--']" /> While alert shows the current value of select combobox, it always passes null value to session.sfs. Can someone please advise what I am doing wrong here, and how to pass this.value to session tag properly? |
|
Hi,
2007/10/9, thirdion1618 <[hidden email]>: > > Hey, > > Am fairly new to Grails, and am stuck on an issue in my first grails app (an > exploratory contacts app). > > I have the following in my list.gsp : > <g:select name="searchfield" > onchange="alert(this.value);${session.sfs=this.value};" you're mixing javascript with java/groovy (the stuff inside ${..}). To really start with java web development skip the "onchange" attribute (javascript) and learn about using Controllers and Views. You need to handle a "request" (either as a normal HttpRequest or as an AJAX-request) to assign a value to a session attribute. To assing the value to a session attribute what you need to do is: * Submit your formular (not 'onchange' except you understand AJAX!) * Read the 'searchfield' parameter inside of the controller action (its the value of the selected option) * Assign this value to a session attribute (inside of the controller or in the the view) > from="${['Firstname', 'Lastname', 'Country', 'Organisation', 'Region']}" > keys="${['Firstname', 'Lastname', 'Country', 'Organisation', 'Region']}" > noSelection="['':'--Choose--']" /> > > While alert shows the current value of select combobox, it always passes > null value to session.sfs. > > Can someone please advise what I am doing wrong here, and how to pass > this.value to session tag properly? > > > -- > View this message in context: http://www.nabble.com/Passing-Javascript-Into-GSP-tags-tf4591118.html#a13106202 > Sent from the grails - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
I was able solve this problem using g:remoteFunction and creating a related controller to update the session attribute. <g:select id="sfid" name="searchfield" onchange="${remoteFunction(action:'changesessionvar',params:'\'val=\' + this.value')}" from="${['Firstname', 'Lastname', 'Country', 'Organisation', 'Region', 'Category', 'OrganisationType', 'Department', 'Position']}" noSelection="['':'--Choose--']" /> I really think that grails should have provisions (via a tag, etc) to inter-mix javascript variables within gsp tags.
|
|
Hi again,
2007/10/9, thirdion1618 <[hidden email]>: > > > I was able solve this problem using g:remoteFunction and creating a related > controller to update the > session attribute. > > <g:select id="sfid" name="searchfield" > onchange="${remoteFunction(action:'changesessionvar',params:'\'val=\' + > this.value')}" from="${['Firstname', 'Lastname', 'Country', 'Organisation', > 'Region', 'Category', 'OrganisationType', 'Department', 'Position']}" > noSelection="['':'--Choose--']" /> > > > To assing the value to a session attribute what you need to do is: > > > > * Submit your formular (not 'onchange' except you understand AJAX!) of course you perfectly understand it, sorry for being a little harsh ;-) Chris --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | See how NAML generates this page |
