| Stable release | 2.2.2 / April 29, 2013 |
|---|---|
| Written in | Groovy |
| Operating system | Cross-platform |
| Platform | Cross-platform (JVM) |
| Type | Web application framework |
| License | Apache License 2.0 |
| Website | grails.org |
Grails is an open source web application framework which uses the Groovy programming language (which is in turn based on the Java platform). It is intended to be a high-productivity framework by following the "coding by convention" paradigm, providing a stand-alone development environment and hiding much of the configuration detail from the developer.
Grails was previously known as 'Groovy on Rails'; in March 2006 that name was dropped in response to a request by David Heinemeier Hansson, founder of the Ruby on Rails framework. Work began in July 2005, with the 0.1 release on March 29, 2006 and the 1.0 release announced on February 18, 2008.
G2One - The Groovy Grails Company - was acquired by SpringSource in November, 2008, and it was later acquired by VMware.
Grails was developed with a number of goals:
Grails was designed to be easy to learn, easy to develop applications and extensible. It attempts to offer the right balance between consistency and powerful features.
Grails has three properties which attempt to increase productivity when compared to traditional Java web frameworks:
Creating web applications in Java traditionally involves configuring environments and frameworks at the start and during development. This configuration is very often externalized in XML files to ease configuration and avoid embedding configuration in application code.
XML was initially welcomed as it provided greater consistency to configure applications. In recent years however it has become apparent that although XML is great for configuration it can be tedious to set up an environment. This may take away productivity as developers spend time understanding and maintaining framework configuration as the application grows. Adding or changing functionality in applications which use XML configuration adds an extra step to the change process next to writing application code which slows down productivity and may take away the agility of the entire process.
Grails takes away the need to add configuration in XML files. Instead the framework uses a set of rules or conventions while inspecting the code of Grails-based applications. For example, a class name which ends with Controller (for example BookController) is considered a web controller.
When using traditional Java web toolkits, it's up to developers to assemble development units, which can be tedious. Grails comes with a complete development environment which includes a web server to get developers started right away. All required libraries are part of the Grails distribution and Grails prepares the Java web environment for deployment automatically.
Grails features dynamic methods on several classes through mixins. A mixin is a method which is added to a class dynamically as if the functionality was compiled in the program.
These dynamic methods allow developers to perform operations without having to implement interfaces or extend base classes. Grails provides dynamic methods based on the type of class. For example domain classes have methods to automate persistence operations like save, delete and find.
The Grails web framework has been designed according to the MVC paradigm.
Grails uses controllers to implement the behaviour of web pages. Below is an example of a controller:
class BookController { def list() { [ books: Book.findAll() ] } }
The controller above has a list action which returns a model containing all books in the database. To create this controller the grails command is used, as shown below:
grails create-controller
This command requests the controller name and creates a class in the grails-app/controller directory of the Grails project. Creating the controller class is sufficient to have it recognized by Grails. The list action maps to http://localhost:8080/book/list in development mode.
Grails supports JSP and GSP. The example below shows a view written in GSP which lists the books in the model prepared by the controller above:
<html> <head> <title>Our books</title> </head> <body> <ul> <g:each in="${books}"> <li>${it.title} (${it.author.name})</li> </g:each> </ul> </body> </html>
This view should be saved as grails-app/views/book/list.gsp of the Grails project. This location maps to the BookController and list action. Placing the file in this location is sufficient to have it recognized by Grails.
There is also a GSP tag reference available.
Grails supports several Ajax libraries including OpenRico, Prototype, Dojo, YUI and ZKGrails. You can use existing tag libraries which create HTML with Ajax code. You can also easily create your own tag libraries.
Grails provides a large number of tag libraries out of the box. However you can also create and reuse your own tag libraries easily:
class ApplicationTagLib { def formatDate = { attrs, body -> out << new java.text.SimpleDateFormat(attrs.format).format(attrs.date) } }
The formatDate tag library above formats a java.util.Date object to a String. This tag library should be added to the grails-app/taglib/ApplicationTagLib.groovy file or a file ending with TagLib.groovy in the grails-app/taglib directory.
Below is a snippet from a GSP file which uses the formatDate tag library:
<g:formatDate format="yyyyMMdd" date="${myDate}"/>
To use a dynamic tag library in a GSP no import tags have to be used. Dynamic tag libraries can also be used in JSP files although this requires a little more work. [1]
The domain model in Grails is persisted to the database using GORM (Grails Object Relational Mapping). Domain classes are saved in the grails-app/domain directory and can be created using the grails command as shown below:
grails create-domain-class
This command requests the domain class name and creates the appropriate file. Below the code of the Book class is shown:
class Book { String title Person author }
Creating this class is all that is required to have it managed for persistence by Grails. With Grails 0.3, GORM has been improved and e.g. adds the properties id and version itself to the domain class if they are not present.
The domain classes managed by GORM have 'magic' dynamic and static methods to perform persistence operations on these classes and its objects. [2]
The save() method saves an object to the database:
def book = new Book(title:"The Da Vinci Code", author:Author.findByName("Dan Brown")) book.save()
The delete() method deletes an object from the database:
def book = Book.findByTitle("The Da Vinci Code") book.delete()
The refresh() method refreshes the state of an object from the database:
def book = Book.findByTitle("The Da Vinci Code") book.refresh()
The ident() method retrieves the object's identity assigned from the database:
def book = Book.findByTitle("The Da Vinci Code") def id = book.ident()
The count() method returns the number of records in the database for a given class:
def bookCount = Book.count()
The exists() method returns true if an object exists in the database with a given identifier:
def bookExists = Book.exists(1)
The find() method returns the first object from the database based on an object query statement:
def book = Book.find("from Book b where b.title = ?", [ 'The Da Vinci Code' ])
Note that the query syntax is Hibernate HQL.
The findAll() method returns all objects existing in the database:
def books = Book.findAll()
The findAll() method can also take an object query statement for returning a list of objects:
def books = Book.findAll("from Book")
The findBy*() methods return the first object from the database which matches a specific pattern:
def book = Book.findByTitle("The Da Vinci Code")
Also:
def book = Book.findByTitleLike("%Da Vinci%")
The findAllBy*() methods return a list of objects from the database which match a specific pattern:
def books = Book.findAllByTitleLike("The%")
The findWhere*() methods return the first object from the database which matches a set of named parameters:
def book = Book.findWhere(title:"The Da Vinci Code")
Grails supports scaffolding to support CRUD operations (Create, Read, Update, Delete). Any domain class can be scaffolded by creating a scaffolding controller as shown below:
class BookController { static scaffold = true }
By creating this class you can perform CRUD operations on http://localhost:8080/book. Currently Grails does not provide scaffolding for associations.
The persistence mechanism in GORM is implemented via Hibernate. As such, legacy databases may be mapped to GORM classes using standard Hibernate mapping files.
Download and installation guidelines for Grails are available on the Grails web site.
Grails provides support scripts to create and execute projects as follows:
grails create-app
This command will request the name of the project and creates a project directory with the same name. Further grails commands can be issued in this directory to create the classes and web pages of the application.
The command grails run-app will run the application on a web server at the URL http://localhost:8080/.
The target audience for Grails is:
Grails is built on top of and is part of the Java platform meaning that it is very easy to integrate with Java libraries, frameworks and existing code bases. The most prominent feature Grails offers in this area is the transparent integration of classes which are mapped with the Hibernate ORM framework. This means existing applications which use Hibernate can use Grails without recompiling the code or reconfiguring the Hibernate classes while using the dynamic persistence methods discussed above. [3]
One consequence of this is that scaffolding can be configured for Java classes mapped with Hibernate. Another consequence is that the capabilities of the Grails web framework are fully available for these classes and the applications which use them.
|
|||||||||||||||||||||||||||||||||||||||||
HOT DESIGNS ▪ Premium designs ▪ Designs by country ▪ Designs by U.S. state ▪ Most popular designs ▪ Newest, last added designs ▪ Unique designs ▪ Cheap, budget designs ▪ Design super sale DESIGNS BY THEME ▪ Accounting, audit designs ▪ Adult, sex designs ▪ African designs ▪ American, U.S. designs ▪ Animals, birds, pets designs ▪ Agricultural, farming designs ▪ Architecture, building designs ▪ Army, navy, military designs ▪ Audio & video designs ▪ Automobiles, car designs ▪ Books, e-book designs ▪ Beauty salon, SPA designs ▪ Black, dark designs ▪ Business, corporate designs ▪ Charity, donation designs ▪ Cinema, movie, film designs ▪ Computer, hardware designs ▪ Celebrity, star fan designs ▪ Children, family designs ▪ Christmas, New Year's designs ▪ Green, St. Patrick designs ▪ Dating, matchmaking designs ▪ Design studio, creative designs ▪ Educational, student designs ▪ Electronics designs ▪ Entertainment, fun designs ▪ Fashion, wear designs ▪ Finance, financial designs ▪ Fishing & hunting designs ▪ Flowers, floral shop designs ▪ Food, nutrition designs ▪ Football, soccer designs ▪ Gambling, casino designs ▪ Games, gaming designs ▪ Gifts, gift designs ▪ Halloween, carnival designs ▪ Hotel, resort designs ▪ Industry, industrial designs ▪ Insurance, insurer designs ▪ Interior, furniture designs ▪ International designs ▪ Internet technology designs ▪ Jewelry, jewellery designs ▪ Job & employment designs ▪ Landscaping, garden designs ▪ Law, juridical, legal designs ▪ Love, romantic designs ▪ Marketing designs ▪ Media, radio, TV designs ▪ Medicine, health care designs ▪ Mortgage, loan designs ▪ Music, musical designs ▪ Night club, dancing designs ▪ Photography, photo designs ▪ Personal, individual designs ▪ Politics, political designs ▪ Real estate, realty designs ▪ Religious, church designs ▪ Restaurant, cafe designs ▪ Retirement, pension designs ▪ Science, scientific designs ▪ Sea, ocean, river designs ▪ Security, protection designs ▪ Social, cultural designs ▪ Spirit, meditational designs ▪ Software designs ▪ Sports, sporting designs ▪ Telecommunication designs ▪ Travel, vacation designs ▪ Transport, logistic designs ▪ Web hosting designs ▪ Wedding, marriage designs ▪ White, light designs E-COMMERCE DESIGNS ▪ Magento store designs ▪ OpenCart store designs ▪ PrestaShop store designs ▪ CRE Loaded store designs ▪ Jigoshop store designs ▪ VirtueMart store designs ▪ osCommerce store designs ▪ Zen Cart store designs CMS DESIGNS ▪ Flash CMS designs ▪ Joomla CMS designs ▪ Mambo CMS designs ▪ Drupal CMS designs ▪ WordPress blog designs ▪ Forum designs ▪ phpBB forum designs ▪ PHP-Nuke portal designs ANIMATED WEBSITE DESIGNS ▪ Flash CMS designs ▪ Silverlight animated designs ▪ Silverlight intro designs ▪ Flash animated designs ▪ Flash intro designs ▪ XML Flash designs ▪ Flash 8 animated designs ▪ Dynamic Flash designs ▪ Flash animated photo albums ▪ Dynamic Swish designs ▪ Swish animated designs ▪ jQuery animated designs WEBSITE DESIGNS ▪ WebMatrix Razor designs ▪ HTML 5 designs ▪ Web 2.0 designs ▪ 3-color variation designs ▪ 3D, three-dimensional designs ▪ Artwork, illustrated designs ▪ Clean, simple designs ▪ CSS based website designs ▪ Full design packages ▪ Full ready websites ▪ Portal designs ▪ Stretched, full screen designs ▪ Universal, neutral designs CORPORATE ID DESIGNS ▪ Corporate identity sets ▪ Logo layouts, logo designs ▪ Logotype sets, logo packs ▪ PowerPoint, PTT designs ▪ Facebook themes VIDEO, SOUND & MUSIC ▪ Video e-cards ▪ After Effects video intros ▪ Special video effects ▪ Music tracks, music loops ▪ Stock music bank GRAPHICS & CLIPART ▪ Pro clipart & illustrations, $19/year ▪ 5,000+ icons by subscription ▪ Icons, pictograms |
| Super Offers |
| Super Offers |
| Custom Logo Design $149 ▪ Web Programming ▪ ID Card Printing ▪ Best Web Hosting ▪ eCommerce Software ▪ Add Your Link |
| © 1996-2013 MAGIA Internet Studio ▪ About ▪ Portfolio ▪ Photo on Demand ▪ Hosting ▪ Advertise ▪ Sitemap ▪ Privacy ▪ Maria Online |