Download presentation
Presentation is loading. Please wait.
Published byJames Walters Modified over 9 years ago
1
Grails Mansura Habiba 13 november 2011
2
Introduction What is Grails? Runs on the Java Virtual Machine Used Java like dynamic language Groovy Inspired by Rubi on rails Created and used by Google 2
3
Feature of Grails Grails is a rapid web application development framework built on Groovy and Spring Grails has full stack environement Grails is modular and extensible through a plugin system Just like Spring Grails deployed in any environment 3
4
Stack 4
5
Full Stack Web Framework 5 Web MVCGSP ViewesServlet Container DatabaseI18n Test SupportDoc Engine GORM (Data Access) Build An easy to use MVC Framework Embedded Servlet Simple but Powerful Build in DB access and Modelling In Memory SQL Database Build in Internationalizartion WiKi based HTML Doc Engine
6
Grails MVC Framework 6 Spring Dispatcher Servlet Grails Dispatcher Servlet Simple Grails Controller Simple Grails Controller Helper User Interface (GSP) Grails Controller Grails Service/ Plug-ins Grails Domain DB GORM Template (Sitemesh) Extends URI Request View Model & View mapping
7
Comparison of Groovy with Ruby and Java ConsiderationJava ( JVM ?)Ruby on Rails Groovy and Grails Reduced Time to Market NoYes Reduced CostsNoYes Long term scalability YesNoYes Recommended for applications currently on Java and PHP YesNoYes 7
8
ConsiderationJava ( JVM ?)Ruby on RailsGroovy and Grails Lines of codes to write (Prototypical form validation example) 2086 ReadabilityLengthy lines of codes make it less readable Small size helps in readabilityGood IDE support and hence increases readability. Also size of code governs readability PerformanceHighComparitively lower than Java and Grails Higher than RoR but lesser than Java Well-structured and updated knowledge base YesNoYes Adaptability with AgileNoYes Enterprise supportYesSmall applications. The support of enterprise technologies is not at the focus of the community Could be used for prototyping and also for real applications In built testing tools availableNoYes Developer availabilityHuge supplyNot as much compared to JavaGroovy is a natural transition for Java developers ScalabilityYesNoYes Richness of API/libraries available YesNoYes Ability to embed in desktop (Java/C++) applications YesNoYes Ease of deploymentNoYes Learning curveYesDepends on the history of the developer. Generally start with the database schema and generate domain objects, view and controller from there Depends on the history of the developer. Start with the domain objects and generate view, controller and database schema. A lot more people can write proper domain classes than proper database schemata. 8
9
Installation (JDK) Download JDK from the following Url Invoke the installer and follow the installation Setup JAVA_HOME as User variable Add % JAVA_HOME %\bin to Path 9
10
Installation (Grails) Download GGTS from the following link http://spring.io/tools/ggts http://spring.io/tools/ggts Unzip the binary Plug and play –No need to set up GRAILS_HOME –No need to modify Path varible –No need to set up Server 10
11
Grails Installation Folder 11 IDE Grails Server Open Source Licence
12
Create a Web Application grails create-app HelloWorld install-plugin spring-security-core s2-quickstart com.grails.tutorial User Role Add properties to generated User Class grails generate-all com.grails.tutorial.User grails run-app Application will be available at http://localhost:8080/HelloWorld 12
13
Grails Web Application: Important files 13
14
Grails Web Application: Url mapping Custome DSL for Mapping URLs to view, controller, action Support rich constraints for mechanism Support HTTP method for REST 14
15
15 Grails Web Application: Url mapping
16
Grails & validation 16 class User { String login String password String email Integer age Date birthDate static constraints = { login size: 5..15, blank: false, unique: true password size: 5..15, blank: false email email: true, blank: false age min: 18 birthDate max: new Date() } ${err} 1 2 3
17
Validating the data : Standerd validation nullable - Ensures the property value cannot be null blank- Prevents empty fields email - Checks for well-formed email addresses inList - Displays a combo-box Unique - Prevents duplicate values in the database 17 min, max - Minimum, maximum value for a numeric field minSize, maxSize Minimum, maximum length for a text field matches - Applies a regular expression against a string value validator - Set to a closure or block to use as a custom validation
18
Grails & Internationalization Grails ships with several message bundles for a whole range of languages within the grails-app/i18n directory. For example: –messages.properties –messages_da.properties –messages_de.properties –messages_es.properties –messages_fr.properties 18 Default
19
19 Grails & Internationalization
20
Reading Messages in the View Reading Messages in Controllers Reading Messages in Tag Libraries 20 def show() { def msg = message(code: "my.localized.content", args: ['Juan', 'lunes']) } def myTag = { attrs, body -> def msg = g.message(code: "my.localized.content", args: ['Juan', 'lunes']) } Grails & Internationalization
21
grails-app/conf/UrlMappings.groovy /grails-app/conf/spring/resources.groovy 21 Grails & Internationalization Category
22
Grails Plugin All available plugin –http://grails.org/plugins/?filter=allhttp://grails.org/plugins/?filter=all Plugins are themeselves Grails applications Plugins are provided with several hooks during install Plugin resources are added to the main application at startup 22
23
Grails Plugin > grails list-plugins > grails install-plugin > grails plugin-info > grails create-plugin 23
24
24
25
Grails Testcase 25
26
Most used Grails Command – grails create-app [project_Name] – grails create-domain-class [qualified_domain_class_Name] – grails generate-all/view/controller [qualified_domain_class_Name] – grails install-plugin [plugin-name] – grails run-app – grails test-app – grails war – grails console 26
27
Grails and Mobile Application Development 27 1.Sencha/ExtJS (www.sencha.com) 2.Grails (www.grails.org) 3.MySQL (www.mysql.org) 4.Tomcat (tomcat.apache.org) 5.Apache (www.apache.org) http://www.cubedrive.com/calendarDemo/
28
SOA and REST with Grails 28
29
Why Grails is Popular 29 InfoQ's Top 20 Web Frameworks for the JVMInfoQ's Top 20 Web Frameworks for the JVM 2013
30
Why Grails is Popular (Cont..) Agile and dynamic language for the Java Virtual Machine Java + Additional features. Makes modern programming features available to Java developers with almost- zero learning curve Supports Domain-Specific Languages and other compact syntax so your code becomes easy to read and maintain 30
31
Why Grails is Popular (Cont..) Makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL Increases developer productivity by reducing scaffolding code when developing web, GUI, database or console applications 31
32
Why Grails is Popular (Cont..) Simplifies testing by supporting unit testing and mocking out-of-the-box Seamlessly integrates with all existing Java objects and libraries Compiles straight to Java byte code so you can use it anywhere you can use Java 32
33
33
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.