Figure 1 shows the resulting directory structure. The command will result in the creation of about KB of files and directories. The idea here is that the framework is going with established Web application development conventions, so it creates files and directories that would be useful in a majority of Web applications. Although some may not like this idea of being forced into a certain structure, this auto-generation based on conventions is where the RAD features of Grails come from. If you take a closer look at these directories, you will see that there are directories for things like controllers, views, tests, configuration files, and tag libraries.
Getting Started with Grails on GlassFish
So the basic structure of you app is now in place. You just fill in the blanks and the application will be ready. Note that the commands that autogenerate directories and files are optional. You can do all the file and directory creation manually. An HSQL database comes built-in with Grails and can be useful for testing simple applications or just trying out Grails. To create a domain class, just run the command grails create-domain-class.
Remember to run this command within your project directory and not in the directory above it.
- Groovy and Grails – A Getting Started Guide.
- Waveguide Handbook;
- Introduction to the Grails Web Framework.
- Reclaiming the L-Word. Sapphos Daughters Out in Africa!
- A Functional Biology of Nematodes.
- Prom Night: All the Way.
- Step 2: Install GGTS IDE and Grails on your home machine and get it running.!
This is a common mistake that, although I have cautioned you, you will commit at least once. The only input you must provide to the create-domain-class command is the class name. Run the command three times, giving Shirt, Trouser, and Cabinet as the names of the three domain classes. These will have just two properties id and version. I will add properties to the classes to make them more representative of a shirt, trouser, and a cabinet.
Listing 1: Cabinet. Listing 2: Trouser. Every Shirt and Trouser belongs to the Cabinet, and the Cabinet has a set of shirts and trousers.
First Edition (January 2007)
The belongsTo property is optional in this case, because in a one-many relationship, Grails always considers the one side as the owner. So you do not need to explicitly state so. Here I have done that just to make the relation obvious. Run the grails generate-all command three times and when asked, provide a domain class name. The generate-all command is supposed to generate the controller as well as the view for each domain class but due to bug Grails 0.
You would have to generate the controller manually by using the command generate-controller for each domain class. These controllers are responsible for handling the requests in the Web application meant for a particular domain class. So ShirtController. The controller now has multiple closures, each mapping to a URI.
Closures is a nice feature of the Groovy language, however it does take some time to get used to it. Listing 4 shows an excerpt from Shirtcontroller. Listing 4: ShirtController. The controller is where you can work with things like requests, sessions, and servletContext that you would be used to working with in Java Web applications.
NOTE: Closures return a value either as an explicit return statement, or as the value of the last statement in the closure body. Do not get confused by the absence of return in the code generated by Grails. Once the controller has finished processing a request, it must delegate to an appropriate view.
For this, Grails uses a convention mechanism. I have hardly written any code, yet I already have a Web application ready. Grails comes with a built-in Resin server, and you can run your application using the grails run-app command. The command will deploy your application to the Resin server and start the server. However, you can just as easily deploy the application to any JavaEE server. I will try to deploy it on Tomcat. For this, all I need to do is run the grails war command and copy the war file that gets generated to the webapps directory in Tomcat!
In this case the war file generated will have the name ClothesMgt. You can display all data, add new shirts, and trousers to a cabinet, edit their values, and also delete the records—all without writing any business logic, view, or data access code. Within just a few minutes you have a proper Web application deployed on a JavaEE server. Cool, eh?! I will now add a new capability and pages to the Web application while reusing the domain classes already in place. To create a new display you need a new controller and view.
Auto-generating views and controllers using domain classes is easily done using the generate-controller and generate-views commands. So I will use the command grails create-controller. When prompted for a controller name, state Display. Grails will create a controller named DisplayController. Edit the controller as shown in Listing 5. In the list closure I set the max param to 10 and then use the dynamic methods Shirt. I then return a Groovy Map that holds two lists, the shirt list and the trouser list.
As a Java developer, when you see Shirt. Our series is a great way to start. InfoQ offers abnormally high royalties and also contract writing opportunities. Email books AT c4media. Join a community of over , senior developers.www.balterrainternacional.com/wp-content/2019-04-17/casa-gay-barcelona-roger.php
Getting Started with Grails by Jason Rudolph
View an example. Grails is an open-source, rapid web application development framework that provides a super-productive full-stack programming model based on the Groovy scripting language and built on top of Spring, Hibernate, and other standard Java frameworks. Ruby on Rails pioneered the innovative coupling of a powerful programming language and an opinionated framework that favors sensible defaults over complex configuration, but many organizations aren't yet ready to stray from the safety of Java or forgo their current Java investments.
Grails makes it possible to achieve equivalent productivity in a Java-centric environment. Jason Rudolph is an Application Architect at Railinc, where he develops software that helps keep trains moving efficiently throughout North America. He recently delivered an industry-wide inspection reporting and management system relied on for operational safety by Fortune railroads, equipment leasing companies, and the Federal Railroad Administration. Enhance your end-user experience by optimizing your application performance. Get a holistic view of your application behavior with Site24x7.
Details if other :. Thanks for telling us about the problem. Return to Book Page. Getting Started with Grails by Jason Rudolph. Grails is an open-source, rapid web application development framework that provides a super-productive full-stack programming model based on the Groovy scripting language and built on top of Spring, Hibernate, and other standard Java frameworks. Ruby on Rails pioneered the innovative coupling of a powerful programming language and an opinionated framework that favors sensi Grails is an open-source, rapid web application development framework that provides a super-productive full-stack programming model based on the Groovy scripting language and built on top of Spring, Hibernate, and other standard Java frameworks.
Ruby on Rails pioneered the innovative coupling of a powerful programming language and an opinionated framework that favors sensible defaults over complex configuration, but many organizations aren't yet ready to stray from the safety of Java or forgo their current Java investments. Grails makes it possible to achieve equivalent productivity in a Java-centric environment.
Over the course of this book, the reader will explore the various aspects of Grails and also experience Grails by building a Grails app. Get A Copy.
Paperback , pages. More Details Original Title. Friend Reviews. To see what your friends thought of this book, please sign up.