Developing Web-applications with Grails framework

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
What is MySQL? MySQL is a database. The data in MySQL is stored in database objects called tables. A table is a collections of related data entries and.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
By: Saurabh Dixit.  Groovy server pages  Taglibs  Validators in grails.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting MySQL – Inserting Data.
2010/11 : [1]PHP with MySQLBuilding Web Applications using MySQL and PHP (W1) PHP with MySQL.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Uploading and Downloading Files.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Form Submission And Saving Data To.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
CS242 SQL. What is SQL? SQL:  stands for Structured Query Language  allows you to access a database  is an ANSI standard computer language  can execute.
Servlets What is a Servlet?
Ruby Reflection and other languages….
Build in Objects In JavaScript, almost "everything" is an object.
COMP 430 Intro. to Database Systems
Databases.
Summary of 1st Visioning Conference
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
A Guide to SQL, Seventh Edition
How to Read a Song with Multiple Verses and Refrain
Developing Web-applications with Grails framework
Title of Training Presentation
Marketing and Recruitment Peer Sharing Call
Gallatin Gallopers 4H Helmet Safety
ActiveParent and CCSD Website Presentation
Servlets Hits Counter 20-Jul-18.
Introduction to Web programming
ELAC Meeting February 17, 2017.
Presented by Raji Arora, Founder STEM Shed
ELAC Meeting September 14, 2017.
SQL – Application Persistence Design Patterns
PDO Database Connections: Getting data out of the database
Title of Training Presentation
JavaScript: Array, Loop, Data File
ISC440: Web Programming 2 Server-side Scripting PHP 3
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Web Systems Development (CSC-215)
PDO Database Connections: Getting data out of the database
Preparation for Entry into .NET Bridging Program (Databases)
CASAS Reports: Assess, Analyze and Adjust
Python I/O.
MySQL Web Application Connecting to a MySQL database
National Mentoring Month Peer Sharing Call
SQL SERVER TRANSACTION LOG INSIDE
Chapter 15 Introduction to Rails.
ELAC Meeting February 11, 2016.
Ap human geography Industrialization and economic development
AP Human Geography Population and Migration Unit
JavaScript MCS/BCS.
AP Human Geography Population and Migration Unit
ELAC Meeting October 15, 2015.
Avery Smith BranchManager Tangipahoa Parish Library
MySQL Web Application Connecting to a MySQL database
CS3220 Web and Internet Programming SQL and MySQL
Mad Scramble for Africa
You can do it in an hour!
Mad Scramble for Africa
AP Human Geography Population and Migration Unit
World Geography Human Geography Unit
SQL – Application Persistence Design Patterns
Introduction to Web programming
Title of Training Presentation
Presentation transcript:

Developing Web-applications with Grails framework Presented by Alexey Vedishchev Displaying Data From the Database American University of Nigeria, 2016

Problem Statement The most common thing we want to do in Grails is to read data from the database and display it to the user. This post is a simple walk-through on how to accomplish this. How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Solution. Step 1: Create a Domain Class We first need to create a domain class. For example: class Person { String firstName String lastName int age } You need to save this under grails-app/domain folder. It is advisable to create a package structure under this folder. How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Solution. Step 1: Create a Domain Class When you start your application, Grails will automatically create a database table for each domain class you have. In our example, the table "person" will be created with columns "first_name", "last_name", and "age". How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Solution. Step 2: Insert Some Data using Bootstrap.groovy For convenience, there is a class in Grails called Bootstrap.groovy. It is under grails- app/conf folder. When your application starts, Grails will execute the code inside it. You can use this to automatically populate your tables with test data. How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Solution. Step 2: Insert Some Data using Bootstrap.groovy import myapp.Person class BootStrap { def init = { servletContext -> if (Person.count() == 0) { new Person(firstName: 'John', lastName: 'Doe', age: 20).save() new Person(firstName: 'Jane', lastName: 'Smith', age: 18).save() new Person(firstName: 'Scott', lastName: 'Robinson', age: 42).save() } def destroy = { How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Solution. Step 2: Insert Some Data using Bootstrap.groovy What the code does is on startup, it will check the number of rows in the person table. If none exists, 3 person records will be inserted. How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Solution. Step 3: Controller Code You can create a simple controller, read data from the database and pass it to your GSP. class PersonController { def index() { def persons = Person.list() [persons:persons] } How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Solution. Step 3: Controller Code The code def persons = Person.list() will fetch all records in person table and store it in persons variable. In Groovy, the last statement you have in a method, is the value that will be returned to the caller. In the example above, the index() method will return a map of values. It contains a single object with name "persons", and the value is the list of items read from the database. This map will be passed to your view (GSP). How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Solution. Step 4: View Code The map of objects passed from the controller will be available inside your view: <!DOCTYPE html> <html> <head> <meta name="layout" content="main"/> <title>Persons</title> </head> <body> <g:each in="${persons}" var="person" status="i"> <h3>${i+1}. ${person.lastName}, ${person.firstName}</h3> <p> Age: ${person.age} </p> <br/> </g:each> </body> </html> How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.

Remarks Our simple example above will have the following output: How presentation will benefit audience: Adult learners are more interested in a subject if they know how or why it is important to them. Presenter’s level of expertise in the subject: Briefly state your credentials in this area, or explain why participants should listen to you.