Example Problem
A contrived for dynamic dropdowns can be described below:
A user would like to select a sports team for a city. The user first selects a value for a dropdown to choose a city. A second dropdown is filtered with the sports teams within that city. An example to clarify:
- The user selects Dallas as the city in the first dropdown. The second dropdown now displays values: Mavericks, Cowboys and Rangers.
- The user selects Pittsburgh as the city in the first dropdown. The second dropdown now displays values Steelers, Pirates, and Penguins.
High Level Design in Grails
Before we get into the details, we can take a step back and describe how we can accomplish a dynamic dropdown in the grails framework.
- On a gsp page, create a select dropdown with the list of cities.
- On change of the city dropdown, send an ajax call to the server with a param of the city selected.
- A controller on the server receives the parameter and looks for teams based on the city selected.
- Return a template with a new select dropdown for the teams, providing a model with the filtered list of teams.
Domain Objects
The domain objects for this example are quite simple: A City object with a name, and a Team object.
package dropdown class City { String name static hasMany = [teams: Team] static constraints = { } } package dropdown class Team { String name static belongsTo = Team static constraints = { } String toString() { name } }
Gsp Page
A gsp page contains a list of the cities directly from a GORM call. This is commonly performed and demonstrated by the default generated grails gsp pages. Note the use of remoteFunction. This is a grails gsp utility which makes an ajax call to the server and provides 'update' for the section of the dom to be updated on return.
For the team dropdown, we will start off with a an empty select tag. Below is a snippet.
<g:select name="city.id" from="${City.list()}" optionKey="id" optionValue="name" noSelection="['':'Choose City']" onchange="${remoteFunction ( controller: 'city', action: 'findTeamsForCity', params: '\'city.id=\' + this.value', update: 'teamSelection' )}" /> .... <td id="teamSelection" valign="top"> <select> <option>Choose Team</option> </select> </td>
Controller used for Filtering
The controller will have a closure which takes in the city id, and then uses it to provide the teams associated with the city. This closure is invoked via ajax. The closure renders a template and a model.
The def dynamicDropdown closure is just used for navigation. By convention its renders the gsp of the same name.
package dropdown class CityController { static scaffold = City // just navigation to the gsp def dynamicDropdown = { } def findTeamsForCity = { def city = City.get(params.city.id) render(template: 'teamSelection', model: [teams: city.teams]) } }Template
The template is used to replace a section of the dom in the gsp. It accepts any model that is provided.
<!-- This template renders a drop down after a city is selected --> <g:select name="team.id" from="${teams}" optionValue="name" optionKey="id"/>
Conclusion
There are multiple ways to accomplish a dynamic dropdown. Native jQuery can be used, or even native JavaScript. I chose to utilize the built-in functions of grails and lessen my dependency on client side programming. This proved to be clean, quick and quite simple!
Grails 2.0.1 complains about this line
ReplyDeleteparams: ''city.id=' + this.value',
Even after getting around that, this code won't dynamically fill the teams dropdown - however, the relationships do work.
Did you test this code? Do you have a working sample project which you might share?
Thanks
This code is working code that i pasted on to the site. Unfortunately the tool i used to format html on to the blog left out a '/' char, and it was escaped.
ReplyDeletethe snipper should lool like this:
params: '\'city.id=\' + this.value',
If you would like a zip of the code, send me an email please. I will be glad to send it to u. I have corrected on the site.
Thanks for catching that!
Can you send me the code. Much appreciated.
ReplyDelete@cmtopinka
ReplyDeletei sent the code to cmtopinka@gmail.com. Is that your email? If not please let me know
Thank you! :)
ReplyDeleteHi
ReplyDeletecan u send me the code to karthiknagtaurus@gmail.com
Hello, can you also email me the code at rachel_bird@taylor.edu?
ReplyDeleteThanks so much.
Plz u send me the code kamonpop@gmail.com
ReplyDeletePLease send me the code at saurabhkr1@yahoo.com . Many Thanks in advance
ReplyDeleteHello, Can you send me the code, please? Thank you
ReplyDeletelletuga15@gmail.com
Hi , can you please send me the code, too? I tried to google it with no luck.
ReplyDeleteerik.marencik[at]gmail[dot]com
i have to create the samething , but the value of first select to be tested. for eg: it belongs to province ="BC" something like that.
ReplyDeleteOne morething , these two select tag to be used in the create.gsp page does it affect other user data already entered?
Can you please give me reply and code to my id :kalpana.vasan@gmail.com
Hi. I was wondering if you could share the source with me as well. Thank you! ahdunn@gmail.com
ReplyDeletesend me please too!
ReplyDeletemihailorama@gmail.com
send me please too!
ReplyDeleterafra_raja@yahoo.com.mx
Hi can you send me the code also. jerika.legasto@gmail.com
ReplyDeleteThank you.
Send me a copy please!
ReplyDeleteelisieldavila@gmail.com
Thank you.
Could you please send a copy of this code to jobrien1956@gmail.com
ReplyDeleteThanks
This comment has been removed by the author.
ReplyDeletePlease send a copy to javier7co@gmail.com
ReplyDeleteThanks
What is the path of the template .gsp file?
ReplyDeleteCould you please send a copy of this code to jool49@gmail.com
Thank you
Please send a copy of the code to andrelink14@gmail.com.
ReplyDeleteThank you
Could you please send a copy of this code to hemantgp@gmail.com
ReplyDeleteThanks
Hello, could you please send a copy of this code to dimitris-ts@hotmail.com
ReplyDeleteThanks you!!
Hello, could you please send a copy of this code to hameedr09@gmail.com
ReplyDeleteThanks you!!
Interesting Article
ReplyDeleteSpring Hibernate Online Training | Hibernate Training in Chennai
Hibernate Online Training | Java Online Training | Java EE Online Training
This is the right blog. it's far very interesting weblog ever. thank you for giving one of these first-rate article. for more information please check the site
ReplyDeleteoracle cloud fusion financials
Usually the blog you posted is very useful to us thanks for posting this blog.
ReplyDeleteTo find Best Training institutes can search in our Calfre.com it is very easy to find the complete details about all Training's Centers Find more information click here
Wow, this blog is very nice I really like your blog and i am Impressed thank you very much for posting this blog.
ReplyDeleteTo find Best Training institutes can search in our Calfre.com it is very easy to find the complete details about all Training's Centers Find more information click here
This post is very informative for everybody. I would like to appreciate your work for good accuracy and got informative knowledge from here.
ReplyDeleteTo find Best Training institutes can search in our Calfre.com it is very easy to find the complete details about all Training's Centers For more information Click Here
I recently came across your blog and have been reading along. I thought I would leave my first comment.
ReplyDeleteJava training in Chennai
Java training in Bangalore
ReplyDeleteYou did well on inspiring writers like me. Please keep on doing such content.
Software testing training in chennai
Salesforce Training in Chennai
Big Data Training in Chennai
Hadoop Training in Chennai
Android Training in Chennai
Selenium Training in Chennai
Digital Marketing Training in Chennai
JAVA Training in Chennai
Best JAVA Training institute in Chennai
PirateBy Supplies Top Famous Cracks, Serial Keys, Patches, Cracked Software, PirateBy also Provide WordPress Nulled Themes & Plugins Absolutely Free.
ReplyDeleteIt’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.
ReplyDeleteRPA Training in chennai |RPA Training course chennai
It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.
ReplyDeleteData science Course Training in Chennai |Best Data Science Training Institute in Chennai
RPA Course Training in Chennai |Best RPA Training Institute in Chennai
AWS Course Training in Chennai |Best AWS Training Institute in Chennai
It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.
ReplyDeletematlab training in chennai
The first course you may want to take advantage of is the PAT testing course, cursos de ti
ReplyDeletewonderful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDeleteAWS training in chennai | AWS training in anna nagar | AWS training in omr | AWS training in porur | AWS training in tambaram | AWS training in velachery
Thanks for sharing this informative content , Great work
ReplyDeleteLeanpitch provides online training inScrum Master during this lockdown period everyone can use it wisely.
Advanced Scrum Master Training
Hi,
ReplyDeleteI things it's an amazing piece of content. I would like to appreciate your efforts.
We are providing wonderfull digital marketing agency. If you are looking for these services we are here for you. Feel free to visit our website.
you described it very beautifully thank you. Yellowstone Coat
ReplyDeleteimpressive
ReplyDeleteJoe Biden Silver Leather Jacket
EasyWay Logistics.!!
ReplyDeleteLooking for a Customs clearance Service, Truck service, Freight forwarder, Shipping a Cargo, Import & Export ..??
Transporters in India
Cargo Agents
Custom Clearing Agents
C&F Agents
Second Hand Container Dealers
Air Cargo Agents
Really very Interesting Article, Thanks for sharing it. Webocity is best website designing company in delhi , Best Website development company in Delhi, We Offer Best Digital Marketing services in Delhi.
ReplyDeleteHailing from the prestigious PGIMER, Chandigarh, Dr. Manish Budhiraja, is a dynamic & experienced Neurosurgeon whose expertise is in complex Brain & Minimally Invasive Spine surgeries. He has specialization in Brain and Spinal Tumor surgeries, Minimally Invasive Spine Surgeries, Spinal trauma and Fixation, Pituitary Tumors and Functional Neurosurgery including Deep Brain Stimulation
ReplyDeleteDoctor Name- Dr. Manish Budhiraja {MBBS, MS (Surgery), M.Ch (Neurosurgery)}
Address- Alchemist Hospital Rd, Sector 21, Budanpur, Panchkula, Punjab 134112
Phone- 7888900544
I will definitely write all these addresses down and try them as soon as I could! Love the remark about the bartender who looks like Johnny Depp! Great post! Mens Shearling Coat
ReplyDeleteDo you need an urgent loan of any kind? Loans to liquidate debts or need to loan to improve your business have you been rejected by any other banks and financial institutions? Do you need a loan or a mortgage? This is the place to look, we are here to solve all your financial problems. We borrow money for the public. Need financial help with a bad credit in need of money. To pay for a commercial investment at a reasonable rate of 3%, let me use this method to inform you that we are providing reliable and helpful assistance and we will be ready to lend you. Contact us today by email: daveloganloanfirm@gmail.com Call/Text: +1(501)800-0690 And whatsapp: +1 (315) 640-3560
ReplyDeleteNEED A LOAN?
Ask Me.
Thanks for sharing informative content, Great work.
ReplyDeleteTo crack Scrum master interview: Scrum master interview questions
Awesome. You have clearly explained …Its very useful for me to know about new things. Keep on blogging.
ReplyDeleteDevops Training in Gurgaon
Docker Kubernetes training in Gurgaon
AWS cloud training in Gurgaon
FullStack Development Training in Gurgaon
It was wonderfull reading your article. Great writing styleIamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder IamLinkfeeder
ReplyDeleteThank you very much for providing important information. All your information is very valuable to me.
ReplyDeleteVillage Talkies a top-quality professional corporate video production company in Bangalore and also best explainer video company in Bangalore & animation video makers in Bangalore, Chennai, India & Maryland, Baltimore, USA provides Corporate & Brand films, Promotional, Marketing videos & Training videos, Product demo videos, Employee videos, Product video explainers, eLearning videos, 2d Animation, 3d Animation, Motion Graphics, Whiteboard Explainer videos Client Testimonial Videos, Video Presentation and more for all start-ups, industries, and corporate companies. From scripting to corporate video production services, explainer & 3d, 2d animation video production , our solutions are customized to your budget, timeline, and to meet the company goals and objectives.
As a best video production company in Bangalore, we produce quality and creative videos to our clients.
Incredibly conventional blog and articles. I am realy very happy to visit your blog. Directly I am found which I truly need. Thankful to you and keeping it together for your new post…
ReplyDeleteAWS Training in Hyderabad
Do you need an urgent loan of any kind? Loans to liquidate debts or need to loan to improve your business have you been rejected by any other banks and financial institutions? Do you need a loan or a mortgage? This is the place to look, we are here to solve all your financial problems. We borrow money for the public. Need financial help with a bad credit in need of money. To pay for a commercial investment at a reasonable rate of 3%, let me use this method to inform you that we are providing reliable and helpful assistance and we will be ready to lend you. Contact us today by email: daveloganloanfirm@gmail.com Call/Text: +1(501)800-0690 And whatsapp: +1 (501) 214‑1395
ReplyDeleteNEED A LOAN?
Ask Me.
thanks for the valueable content. information is nicely written and understandable!
ReplyDeleteAre you looking for the best digital marketing training in Jaipur? You are in right place. Dzone is offering you the best digital marketing training with a great learning experience and practical exposure. We offer you practise oriented real-time digital marketing course. To know more contact us at 9829708506
Or can visit our website: http://bit.ly/digitaldzone
DO YOU NEED A PERSONAL/BUSINESS/INVESTMENT LOAN? CONTACT US TODAY VIA WhatsApp +19292227023 Email drbenjaminfinance@gmail.com
ReplyDeleteHELLO
Loan Offer Alert For Everyone! Are you financially down and you need an urgent credit/financial assistance? Or are you in need of a loan to start-up/increase your business or buy your dream house. Are you in search of a legit loan? Tired of Seeking Loans and Mortgages? Have you been turned down by your banks? Have you also been scammed once? Have you lost money to scammers or to Binary Options and Cryptocurrency Trading, We will help you recover your lost money and stolen bitcoin by our security FinanceRecovery Team 100% secured, If you are in financial pains consider your financial trauma over. We Offer LOANS from $3,000.00 Min. to $30,000,000.00 Max. at 2% interest rate NO MATTER YOUR CREDIT SCORE. GET YOUR INSTANT LOAN APPROVAL 100% GUARANTEED TODAY VIA WhatsApp:+19292227023 Email: drbenjaminfinance@gmail.com
Fantastic article! Many thanks for the exciting blog posting! I like the informative article from you. Will look forward for more updates. Good Job, Keep it up..
ReplyDeleteui ux course
PHP Course
ui ux course
.net course singapore
python course
Welcome to CapturedCurrentNews – Latest & Breaking India News 2021
ReplyDeleteHello Friends My Name Anthony Morris.latest and breaking news
Very Informative blog thank you for sharing. Keep sharing.
ReplyDeleteBest software training institute in Chennai. Make your career development the best by learning software courses.
power bi course in Chennai
Docker Training in Chennai
android training in chennai
ios training in chennai
Xamarin Training in Chennai
msbi training in chennai
Informatica Training in Chennai
This article explains to you the Scope of Digital Marketing in India 2020 and the career opportunities on Digital Marketing.
ReplyDeleteI simply wanted to thank you so much again. I am not sure the things
ReplyDeletethat I might have gone through without the type of hints revealed by
you regarding that situation.
oracle course in chennai
ASP Dot Net Training in Chennai
C Sharp Training in Chennai
Appreciative for sharing your contemplations. I really like your undertakings and I will hold tight for your further evaluations. Everything is incomprehensibly open with a positive depiction of the troubles. It was really enlightening. Your site is important. Thankful for sharing! Nasa jacket
ReplyDeleteNice Blog!
ReplyDeleteThanks you very much for sharing valuable information.
Keep on posting...
private finance in Chennai
Private Finance In Tamilnadu
Business loan in Chennai
Well, Great idea with excellent article! Keep on posting, Waiting for your next blog.
ReplyDeletejob consultants in coimbatore
Recruitment Consultants in Coimbatore
IT Staffing Companies in Coimbatore
All things considered I read it yesterday yet I had a few musings about it and today I needed to peruse it again in light of the fact that it is very elegantly composed.
ReplyDelete360DigiTMG, the top-rated organisation among the most prestigious industries around the world, is an educational destination for those looking to pursue their dreams around the globe. The company is changing careers of many people through constant improvement, 360DigiTMG provides an outstanding learning experience and distinguishes itself from the pack. 360DigiTMG is a prominent global presence by offering world-class training. Its main office is in India and subsidiaries across Malaysia, USA, East Asia, Australia, Uk, Netherlands, and the Middle East.
ReplyDeleteThank you for shearing post amazing this is post very useful for me. Cruella Jacket
ReplyDeleteI am glad to discover this page. I have to thank you for the time I spent on this especially great reading !! I really liked each part and also bookmarked you for new information on your site.
ReplyDeleteTableau training institute in Hyderabad can be a ticket to your fortunate tableau career. Dashboards, tableau desktop, Tableau online, charts, and many other key features of tableau this is best for you have interest visit my website link http://tableautrainings.in/
ReplyDeleteI Appreciate this post. It's a very informative and useful.
ReplyDeleteAmazing, glad realm. I would at the rear of to write down when this as well - taking time and cement hard play a situation to make a comfortable article... anyway I put things off something over the top and in no way, shape or form appear to profit started. much thanks to you despite the fact that. thanks! Driver Toolkit Crack
ReplyDeletemuch obliged to you for taking the length to examine this, I have a firm opinion roughly it and commend getting to know additional going vis- On the off chance that feasible, as you benefit speed, could you considerations refreshing your weblog long past helper assessment? it's miles the total obliging for me. thanks! Office 2010 Activation Crack
ReplyDeleteKeep on posting! looking to read more blog like this,...
ReplyDeleteDigital Marketing | Web Design and Development | Software Development
Hey! This blog is more informative and user friendly
ReplyDeleteThank you so much for giving this information to me..
biofit vitamins for adults
keravita pro 101 reviews
synogut pills
is lean belly 3x safe
cera care health care reviews
shallow sleep syndrome resurge
altai balance blood sugar support reviews
dentitox pro real reviews
Does java burn work
exipure amazon
Hey! This blog is more informative and user friendly
ReplyDeleteThank you so much for giving this information to me..
Compression Calf Sleeves Running
Best Eye Masks
Shapewear Panty
Swimsuit Bra Pad
Sleeveless Tank Top
Seat Pads For Chairs
React JS Training in Hyderabad
ReplyDeleteInformative blog post
ReplyDeleteInformative blog post
ReplyDeleteI really appreciate your valuable efforts and it was very helpful for me. Thank you so much...!
ReplyDeleteUncontested Divorce Process in Virginia
Cheap Uncontested Divorce in VA
Very Informative blog thank you for sharing
ReplyDeleteembbeded system training in chennai
Very Informative blog thank you for sharing. Keep sharing.
ReplyDeleteInformatica MDM Training in Chennai
Informatica Data Quality Training in Chennai
Nice article
ReplyDeleteGuidelines
http://www.jeevisoft.com
Step-by-Step Hacking Tutorials about WiFi hacking,
ReplyDeleteKali Linux, Metasploit, exploits, ethical hacking, information security, malware analysis and scanning
hacking Tutorial
Web, Android & iOS Development Company in Rajkot
ReplyDeleteYou have performed a great job. I will certainly dig it and individually suggest my friends. I’m sure they will be benefited from this web site. Grease Pink Ladies Jacket
ReplyDeleteI wholeheartedly congratulate the writer of this post for explaining the difficult concepts of data science in a simple and easy-to-understand manner. My only regret is that I didn’t read this post earlier. I have made many career decisions in my life after reading this, and have no regrets whatsoever to date.data science course in KL
ReplyDeleteIT is really nice informative.Areenadesign
ReplyDeleteThanks for the post.
ReplyDeleteace2three plus apk download
88 fortunes slot review
white label poker software
parts of a roulette wheel
liberty slots review
suncoast bingo cash ball
Thanks for the post.
ReplyDeletewheel of fortune bingo
free online jackpot
abradoodle bingo tips
buffalo creek casino sports book
bingo clash code
sycuan casino bingo
Thank you sharing the informative article. Jason Momoa Snakeskin Jacket This is useful article for us.
ReplyDeleteKids can learn a lot of fresh and intriguing things from this area. You are doing wonderful job for the new generation of kids, which makes me pleased. Post more fantastic blogs like this.Star Trek Picard Season 3 Leather Jacket
ReplyDeletethis is an incre 토디즈
ReplyDeletei absolutely tha 먹튀검역소먹튀제보
ReplyDeletei relished, i would clearly like a good deal extra statistics with this, specifically argue along (not too i simply would need…haha). You truely placed the state-of-the-art spin with a topic thats been discussed for decades. Super stuff, just exquisite! It's miles a totally thrilling weblog publish. I often visit your posts for my project's help approximately diwali bumper lottery and your outstanding writing competencies actually go away me bowled over เพื่อนฟุตบอล
ReplyDeleteThanks for sharing this post. Know about Bitwissend, web development company in cochin.
ReplyDeleteBlogs can be an outlet for satire, providing readers with light-hearted content to brighten their day. Nord VPN Offer Blogs can document personal journeys, such as weight loss transformations.
ReplyDeleteThanks for sharing this post. Know about Kidangeth Enterprises, steel door dealers in Kottayam.
ReplyDeleteyour information is so useful. thanks for sharing
ReplyDeleteMERN Stack Course In Hyderabad
This blog can help each and every readers and thank you for sharing this informative content, it was really worth reading it. Here we present our informative blog on Nepal to Bhutan travel to have a wonderful reading.
ReplyDeleteyour information is so useful. thanks for sharingCreative designer in Bhutan
ReplyDeleteUnlock seamless transactions with WebPays – among the best credit card payment solution ! Choose WebPays for a streamlined payment experience that enhances your bottom line. Bookmark your success today!
ReplyDeleteExperience greater control over security rules and customization with white-label payment gateway solutions from ITIO Innovex. Contact us now to get the best deal to delight and win more customers.
ReplyDeleteFor the most current and accurate information on Kenya trade statistics, I recommend checking Import Globals. For more information about global import export data visit our website.
ReplyDeleteKenya Import Data
Fantastic post! Your insights really resonate with me and have given me a fresh perspective on the topic breast nipple shield. Looking forward to reading more from you!
ReplyDeleteEmbedded system training covers the design, development, and programming of embedded systems, which are specialized computing systems designed to perform specific tasks within larger systems or devices. Training typically includes topics such as microcontroller architecture, firmware development, real-time operating systems, device drivers, and interfacing with peripherals.
ReplyDeleteGreat work, Thanks for sharing this informative content . embedded systems course in hyderabad.
ReplyDeleteI’ve read about this topic several times, but never has it been presented in such a clear and straightforward manner. The writer really did an exceptional job of breaking it down. It’s rare to find such a well-explained piece—truly impressed! Visit our link for ISO 9001 Certification In Saudi Arabia
ReplyDeleteThis blog is truly wonderful. I've read it aloud to my friends and my relatives.
ReplyDeleteCool and that i have a tremendous offer you: How Much Are House Renovations Stardew Valley log home restoration near me
ReplyDeleteThis is the best blog design and article. Very nice job. Thank you very much...
ReplyDeleteAWS Devops training in hyderabad
Jaypee India Ltd makes strong concrete mixer machine for building work. These machines mix cement, sand, and water evenly to make good concrete. Easy to use and long-lasting, Jaypee concrete mixers help save time and give the best results for your projects.
ReplyDelete