Building Rich Internet applications with Grails, part 1th: Building Web Applications with Grails and Flex

Source: Internet
Author: User
Tags soap representational state transfer web services grails

Introduction: Rich Internet applications (Rich Internet Applications,ria) ensure the dynamic and functional nature of desktop applications through browsers. One of the main features of RIA is to move the presentation layer to the client and support it with the robust RESTful service layer on the server. This idea is spread through popular words such as Soui (Service oriented User Interface) and SOFEA (Service oriented Front end architecture).

About this series

This series explores application architectures that use a service-oriented architecture (SOA) implemented by the Grails framework at the back end. Learn how Grails greatly simplifies the creation of Web applications, especially Web services. This backend can be easily connected to any pure client application. In the 1th part, you will use Adobe Flex to create an application that can use Flash Player. In part 2nd, you will create a front-end with pure JavaScript via Google Web Toolkit.

Prerequisite

In this article, you will build Web applications using Grails and Flex. The Grails framework is based on the Groovy programming language, which is a dynamic language for the Java™ platform. It's better to be familiar with Groovy, but not necessary. Learning about Java or other dynamic languages, such as Ruby or Python, can be a great help. This article uses Grails 1.0.3. Grails can be used with many databases or application servers, but this article does not need to provide them because they are already shipped with grails. The front end is built with Flex. Flex is an application framework that uses the ActionScript programming language, which runs on Flash Player. Again, it doesn't matter if you are unfamiliar with Flex and ActionScript. Familiarity with Java and JavaScript facilitates learning Flex. You need Flex SDK 3.2 or later to compile the code for this article. To run the application built in this article, you must have Flash Player 10.0 or later.

Architecture

Many businesses are scrambling to adopt Service Oriented Architecture (SOA). SOA makes architecture more agile and facilitates rapid business development. Of course, your organization may have another pressing plan: to implement the user interface as a modern, rich Internet application. The two popular technologies of SOA and RIA are not easily integrated. But it turns out that they can work together well. You can use SOA design to deploy services to an application server. You can also move all the presentation logic to the client and create an RIA using powerful front-end technologies such as Flex. That's what you need to do in this series, and now start by creating a Web service with Grails.

WEB Services

When many developers hear the term Web service, they think of SOAP (simple Object Access Protocol). Soap has a negative meaning in the minds of many developers because they think of soap as a large, complex technology. But that's not how WEB services work. REST (representational state Transfer) Web services are generally popular because their semantics are simple. They are easy to create and use. They can use XML like soap, but use Plain old XML (POX), unlike soap, with fancy wrappers and headers. The Grails framework makes it very easy to create this kind of Web service, so we now start with the grails domain model.

Grails Domain Model

Grails is a common Web development framework. Many WEB applications use relational databases to store and retrieve data that is used in an application, so Grails uses powerful Object relational Modeling (ORM) technology, known as GORM. With GORM, you can easily model domain objects and persist them into any relational database, but no longer need to process SQL. GORM uses a popular Hibernate library to generate database-specific, optimized SQL, and to manage the lifecycle of domain objects. Before using GORM, let's start with a quick discussion of the application that will be created, and what needs to be modeled using GORM.

In the sample application, you will create a WEB application that mimics the capabilities of the popular site Digg. On Digg, users can submit news links (Web pages). Then other users can read the news and vote for or against them. Your application will have these basic features. It allows people to submit news anonymously and vote on it, so there is no need to model the user and model the news. The following is a GORM model for the news in the sample application, as shown in Listing 1.

Listing 1. News model

class Story {
   String link
   String title
   String description
   String tags
   String category
   int votesFor
   int votesAgainst
}

This is all the code needed to model a domain object. You want to declare its properties and the types of these properties. This allows Grails to create a table for you and a dynamic creation method for reading and writing data from that table. This is one of the main benefits that Grails offers. You only need to place the data modeling code somewhere, without having to write any template code for simple read and write. Now that the domain model is ready, you can create some business services that use the domain model.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.