Grails tutorial for beginners
Grails tutorial presents a latest language Grails to develop web applications. Grails is an open source framework based language on Groovy and Java. It also supports MVC architecture for developing web application. This tutorial will describe more details about Grails and represent a simple web application with Grails.
1. Groovy
Groovy is a dynamic object-oriented programming language for the Java platform. It is compiled on Java Virtual Machine (JVM) byte code and integrates with all existing Java classes and libraries.
2. Grails MVC
Grails uses Spring MVC framework as the underlying web application framework to implement the web applications based on Model-View-Controller (MVC) design pattern. It includes three core framework components: Controller, Domain, and Grails Servlet Page. The diagram below shows how different part of Grails works together.

2.1. Controller
The GrailsDispatcherServlet uses SpringDispatcherServlet to bootstrap the Grails environment. There is a single Spring MVC controller called SimpleGrailsController which handles all Grails controller requests. The SimpleGrailsController delegates to a class called SimpleGrailsControllerHelper that actually handles the client request and look up a controller for the request. The Controller which is responsible for transferring the domain to view, also determines which gsp should render the view.
2.2. Domain
In Grails application Domain stores the data that can be used by controllers and views. Controllers might create a model or may be just process them.
2.3. Groovy server pages
Groovy server pages creates a view for the client response. GSP is responsible for how to display the model to user. It could use grails tags besides any other UI grails plugin.
3. Grails Simple Application
This example is implemented in Groovy/Grails Tool Suite and using Grails 2.4.4. Now, lets create a simple application with Grails.
First, create a Grails Project in GGTS. The GGTS includes Grails, so, if you wish to use a different version of Grails you need to install it and update the new Grails path in GGTS.
3.1. Controller
We have one controller here. The UserController
is responsible to handle client requests and return proper result when they submit the form. There is a save method which defined with def
. When we declare the return type as def
, it means the method can return any type of object. Inside the method, an instance of User class is created and parameters are set in the domain object and transfered to the view.
UserController.groovy
package com.java.code.sample class UserController { def index() { } def save() { def user = new User(params) user.save() render (view: "user", model: [user: user]) } }
3.2. Model
Creating a domain class is very simple in Grails as there is no need to define setter and getter methods. Grails will handles it for the application.
User.groovy
package com.java.code.sample
class User { String firstName String lastName }
3.3. View
The following gsp
file represents a form to user which includes two items with the same name as model attributes.
index.gsp
<!DOCTYPE html> <html> <head> <title>Welcome to Grails Tutorial</title> <style> .form, .text-field, .submit{ margin: 20px; } </style> </head> <body> <g:form name="form" controller="user" id="form"> <div class="text-field"><label>First Name: </label><g:textField name="firstName" value="${firstName}" /></div> <div class="text-field"><label>Last Name: </label><g:textField name="lastName" value="${lastName}" /></div> <div class="submit"><g:actionSubmit value="Submit" action="save"/></div> </g:form> </body> </html>
Grails uses ${ }
to to get model attributes which is firstName
and lastName
here. When we use
user.gsp
<!DOCTYPE html> <html> <head> <title>User page</title> <style> .user-panel{ margin: 20px; } </style> </head> <body> <div class="user-panel"> Welcome ${user.firstName} ${user.lastName}! </div> </body> </html>
3.4. Run the web application
Now, it is time to run the web application. To run the web application, click on the Grails Command in the Toolbar and type run-app in the popup.
And here are the pages.
3.4.1. Index page

3.4.2. User page

I see you don’t monetize your website, don’t waste your
traffic, you can earn additional bucks every month because you’ve
got hi quality content. If you want to know what is the best adsense alternative, type
in google: Mertiso’s tips
I have noticed you don’t monetize your blog, don’t waste your traffic, you can earn extra bucks every month because you’ve got hi quality content.
If you want to know how to make extra bucks, search for: Mertiso’s tips best
adsense alternative
От каскадных вращений до многочисленных бонусных раундов, Gate Of
Olympus обещает нескончаемый азарт и прибыль.
Cenforce 50mg without preion – Medication safety audits should assess the effectiveness of medication reconciliation processes during hospital admissions and discharges
Вы когда-нибудь задумывались, как бы выглядела схватка
между Зевсом и Аидом в мире азартных игр?
Онлайн-слот “Zeus vs Hades” предоставляет уникальную возможность узнать это на
практике.
If yoᥙ desire to increase yoսr knowledge simply қeep visiting this website and be updated with the most recent news posted hеre.
Here is my homepage; Shifter promo
Bioprocessing equipment is vital for the production of biopharmaceuticals, including monoclonal antibodies. https://community.atlassian.com/t5/user/viewprofilepage/user-id/5366266 vidalista
Hi there! This article couldn’t be written any better! Looking at this post reminds me of my previous roommate! He constantly kept talking about this. I’ll forward this article to him. Pretty sure he will have a very good read. Thanks for sharing!
I have been surfing online more than 3 hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my opinion, if all site owners and bloggers made good content as you did, the net will be much more useful than ever before.
If some one desires expert view regarding blogging and site-building then i suggest him/her to pay a visit this blog, Keep up the nice job.
This design is spectacular! You certainly know how to keep a reader entertained. Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job. I really enjoyed what you had to say, and more than that, how you presented it. Too cool!
It is remarkable, rather the helpful information
Pretty section of content. I just stumbled upon your web site and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently rapidly.
Excellent way of telling, and fastidious post to get facts about my presentation subject, which
i am going to convey in institution of higher education.
Useful info. Fortunate me I found your site by chance, and I am stunned why this coincidence did not happened in advance! I bookmarked it.
ivermectin sheep drench https://community.alteryx.com/t5/user/viewprofilepage/user-id/524801/ albuterol inhaler
Hi there! I just would like to give you a huge thumbs up for the great info you’ve got here on this post. I will be coming back to your site for more soon.
I’m not sure where you are getting your info, but good topic. I needs to spend some time learning more or understanding more. Thanks for fantastic information I was looking for this information for my mission.
It is simply excellent phrase
I blog often and I truly thank you for your information. Your article has truly peaked my interest.
I am going to take a note of your blog and keep checking for new information about once a week.
I opted in for your Feed too.
cat casino официальный сайт
]deloteca.ru
https://car-rental-limassol.bloggazzo.com/23276164/car-rental-limassol-exploring-the-convenience-and-flexibility
Hi there! Would you mind if I share your
blog with my twitter group? There’s a lot of
people that I think would really enjoy your content.
Please let me know. Thanks
Hey there! I’ve been reading your weblog for some time now and finally
got the courage to go ahead and give you a shout out from Atascocita Tx!
Just wanted to say keep up the excellent work!