Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
intoduction to Grails Framework
1. An Introduction To Building
Groovy Web Applications
With Grails
Harshdeep Kaur
2. www.company.com
OVERVIEW
• Grails is a web application framework
• Friendly for beginners to learn.
• Support a more agile development approach.
• MVC framework based on Groovy/Java
• Heavily inspired on Rails framework
• But takes advantage of Java technology like
Spring and servlets
Company
LOGO
3. www.company.com
What is GrailsCompany
LOGO
Grails is an open source web application framework
Built on the Java Platform
Groovy as the primary language
Java can also be used and intermixed with Groovy
seamlessly
Favour's Convention over Configuration
Similar in spirit to Ruby on Rails
Grails having the following features
Rapid, Robust, Dynamic
Powerful features
Integrated ORM / NoSQL support, a powerful view technology, plugins, and
Spring-powered dependency injection
Domain-Specific Languages
Expressive Domain Specific Languages (DSLs) used for validation, querying,
markup rendering etc.
4. www.company.com
Rapid Development
As Grails is inspired by the RAILS principle, it
provides 52 commands to make your life easier:
grails create-app
grails create-domain-class
grails create-controller
grails install-plugin
grails war
5. www.company.com
Grails is Robust
Grails builds upon proven technology:
Groovy - open source dynamic language for the Java Virtual Machine
that offers a flexible Java-like syntax
Spring Framework - Dependency injection services
Hibernate - an Object Relational Mapping (ORM) Framework
SiteMesh - interface layout and theming facilities
+=
6. www.company.com
Why It Is Dynamic
• Changes made in Controllers and Views are instantly
visible - Domain Classes, Bootstrap and Configuration require a
recompile
7. www.company.com
Why grails
Grails aims to improve productivity over
conventional Java Frameworks by:
eliminating XML configuration - Convention over
Configuration. For example, a class name which ends with Controller (e.g.
BookController) is considered a web controller
Scaffolding: Scaffolding utilities provided by Grails is a great advantage
when building prototypes to validate the idea; or to build Admin interfaces.
ready to use development environment - Grails comes with
a complete development environment which includes a webserver and a
database
8. www.company.com
Model View Controller?
MVC is a software architectural pattern which dates
back to 1979 and is widely adopted. It separates:
Data - The model manages the behavior and data of the application
domain.
User Interface - The view renders the model into a form suitable for
interaction, typically a user interface element
Application Logic - The controller receives user input and initiates
a response by making calls on model objects.
13. www.company.com
Groovy Language
Is an agile and dynamic language for the Java Virtual Machine
Additional power features inspired by languages like Python, Ruby and
Smalltalk
Everything is an object no primitive types.
Optional Typing – If not explicitly specified assumed to be java.lang.Object
Can be compiled to Java byte code
Groovy classes are Java classes
Lots of new languages features
GPath, GString, internal iterators, closures, Meta‐
Object Protocol (MOP), and many others
14. www.company.com
Groovy Syntax
Semicolons- use of semicolons ( ; ) in Groovy is completely optional .
Data type declaration-When creating an object, it’s type doesn’t have to be
defined explicitly. By using the def-keyword, Groovy will automatically detect what object
type has to be used
Groovy String- The Groovy String (Also called “GString”) allows for any type of
logic to be integrated in the String definition. This can be done with the dollar symbol
( $ ) and (optional) braces ( { } ). The difference between a String and a GString is
automatically recognized by Groovy.
15. www.company.com
CollectionsGroovy Syntax
Collections- Groovy acknowledges three different types of collections
Lists- are no different from the ones used in Java.
Maps- are no different from the ones used in Java.
Ranges- a range defines a start and an end point.
Loops- Because of Groovy’s origin in Java, it natively supports both the
for- and while-loop.
Groovy’s for-each loops though, have a slight difference in syntax
Groovy has some special capabilities for collections- each method
executes a given closure for each of the item the list.
16. www.company.com
Domain classes are central to a
Grails application
Located in grails app/domain‐
All attributes persistent unless
marked in the transients property
No getters and setters necessary
Validators: specified in
constraints
GORM mapping: customized in
the mapping property
Domain Model Object
17. www.company.com
GROM
Grails Object Relational Mapping
Leverages Hibernate
Automatically maps domain objects to database
Provides query and update facilities
Finding objects in the persistence store (findBy…
methods).
Persistence lifecycle methods (save,update,delete).
Criteria and HQL query facilities.
Declare properties for your domain objects
The id or version properties are injected
automatically.
All properties are not null/required by default
19. www.company.com
The Controllers
Handles HTTP requests and
determines rendering
responsibility
Many objects are available to
your controller closures log,
params , request , response
session servlet-Context ,
flash
21. www.company.com
The Service Layer
Allows for centralization of application
behavior
Necessary component in any non trivial Grails‐
application
Transactional by default, set through the
transactional property
22. www.company.com
Errors and Validation
Built upon Spring’s validation framework
org.springframework.validation package
Domain objects have validation baked in
save() and validate() methods trigger validation
Validation errors populate errors property on
domain object Errors
Interrogate the domain object instance hasErrors() method and error property
def user = new User(params)
if (user.validate())
{ // do something with user }
else {
user.errors.allErrors.each { println it } }
23. www.company.com
Database Connectivity
JDBC is used for communicating with databases
HSQLDB: default data source
DataSource.groovy
Configuration of Data Sources for all your environments
24. www.company.com
Views And Groovy Server Pages
Similar to JSPs
Utilizes GPath and GStrings and other cool Groovy language features
Automatic discovery of Grails taglibs
Support for templates
Small snippets of view code that other views canuse
Useful for AJAX responses
25. www.company.com
The Views
’’ff’’ff
Form tag Go to mapping register inGo to mapping register in
customer controllercustomer controller
Go to mapping register inGo to mapping register in
customer controllercustomer controller
You can create your own tags by creating
new tag libraries
You can create your own tags by creating
new tag libraries
26. www.company.com
Demo of grails/groovy
Set configuration for the application through:-
1.BuildConfig.groovy
2.DataSource.groovy
Uncomment this
Add
Dependencies
and plugins
here