1 / 33

Grails

Grails. Mansura Habiba 13 november 2011. 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. Feature of Grails.

bary
Télécharger la présentation

Grails

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Grails Mansura Habiba 13 november 2011

  2. Introduction What is Grails? • Runs on the Java Virtual Machine • Used Java likedynamiclanguageGroovy • InspiredbyRubi on rails • Createdandusedby Google

  3. Feature of Grails Grails is a rapid web applicationdevelopmentframework built on Groovyand Spring Grails has full stack environement Grails is modularandextensiblethrough a plugin system Just like Spring Grailsdeployed in any environment

  4. Stack Grails Gant (GroovyAnt) Controller Domain View (gsp) Service plugin SiteMesh Spring MVC,Beans, Txns JUnit GORM Hibernet HSQLBD Servlet Groovy Apache Common JDK JAVA EE JAVA Virtual Machine

  5. Full Stack Web Framework Embedded Servlet An easy touse MVC Framework Simple but Powerful Web MVC GSP Viewes Servlet Container Build in DB access andModelling Build in Internationalizartion GORM (Data Access) Database I18n In Memory SQL Database Build Test Support Doc Engine WiKibased HTML Doc Engine

  6. Grails MVC Framework Spring DispatcherServlet Extends GrailsDispatcherServlet View URI Request Simple Grails Controller URI Request Model & View Simple Grails Controller Helper User Interface (GSP) Grails Controller Grails Service/ Plug-ins DB Grails Domain Template (Sitemesh) mapping GORM

  7. Comparison of Groovy with Ruby and Java

  8. Installation (JDK) Download JDK from the followingUrl Invoke the installerand follow the installation Setup JAVA_HOME as User variable Add % JAVA_HOME %\bin toPath

  9. Installation (Grails) • Download GGTS from the following link http://spring.io/tools/ggts • Unzip the binary • Plug andplay • No needto set up GRAILS_HOME • No needtomodifyPathvarible • No needto set up Server

  10. Grails Installation Folder IDE Grails Server Open Source Licence

  11. Create a Web Application

  12. Grails Web Application: Important files

  13. Grails Web Application: Urlmapping Custome DSL forMappingURLsto view, controller, action Support richconstraintsformechanism Support HTTP methodfor REST

  14. Grails Web Application: Urlmapping

  15. Grails & validation 1 <g:hasErrorsbean="${user}"> <ul> <g:eachError var="err" bean="${user}"> <li>${err}</li> </g:eachError> </ul> </g:hasErrors> 2 <div class="fieldcontain${hasErrors(bean: userInstance, field: 'firstname', 'error')} "> <label for="firstname"> <g:messagecode="user.firstname.label" default="Firstname" /> </label> <g:textFieldname="firstname" value="${userInstance?.firstname}" /> </div> 3 <g:renderErrorsbean="${user}" /> class User { String login String password String email Integerage DatebirthDate staticconstraints = { login size: 5..15, blank: false, unique: true password size: 5..15, blank: false email email: true, blank: false agemin: 18 birthDate max: new Date() } }

  16. Validating the data : Standerd validation • min, max -Minimum, maximum value for a numericfield • minSize, maxSizeMinimum, maximum length for a textfield • matches -Applies a regularexpressionagainsta string value • validator -Set to a closure or block to use as a customvalidation nullable - Ensures the property value cannot benull blank-Prevents empty fields email - Checks for well-formed email addresses inList -Displays a combo-box Unique -Prevents duplicate values in the database

  17. Grails & Internationalization Default • Grailsshipswithseveralmessagebundlesfor a whole range of languageswithin the grails-app/i18n directory. For example: • messages.properties • messages_da.properties • messages_de.properties • messages_es.properties • messages_fr.properties

  18. Grails & Internationalization

  19. Grails & Internationalization <g:message code="my.localized.content" args="${ ['Juan', 'lunes'] }" /> def show() { defmsg = message(code: "my.localized.content", args: ['Juan', 'lunes']) } defmyTag = { attrs, body -> defmsg = g.message(code: "my.localized.content", args: ['Juan', 'lunes']) } Reading Messages in the View Reading Messages in Controllers Reading Messages in Tag Libraries

  20. Grails & Internationalization <g:linkmapping="storeCategory"params="[lang:'en', category:'new']">Category</g:link> grails-app/conf/UrlMappings.groovy /grails-app/conf/spring/resources.groovy

  21. GrailsPlugin • Allavailableplugin • http://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. GrailsPlugin > grails list-plugins > grailsinstall-plugin <name> > grailsplugin-info <name> > grailscreate-plugin

  23. Grails Testcase

  24. Most usedGrailsCommand • grailscreate-app [project_Name] • grailscreate-domain-class [qualified_domain_class_Name] • grailsgenerate-all/view/controller [qualified_domain_class_Name] • grailsinstall-plugin [plugin-name] • grails run-app • grails test-app • grails war • grails console

  25. Grailsand Mobile Application Development Sencha/ExtJS (www.sencha.com) Grails (www.grails.org) MySQL (www.mysql.org) Tomcat (tomcat.apache.org) Apache (www.apache.org) http://www.cubedrive.com/calendarDemo/

  26. SOA and REST with Grails

  27. WhyGrails is Popular InfoQ's Top 20 Web Frameworks for the JVM 2013

  28. WhyGrails 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

  29. WhyGrails 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

  30. WhyGrails 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

More Related