By: Saurabh Dixit.  Groovy server pages  Taglibs  Validators in grails.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
Chapter 51 Scripting With JSP Elements JavaServer Pages By Xue Bai.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Phonegap Bridge – File System CIS 136 Building Mobile Apps 1.
. If the PHP server is an server or is aware of which server is the server, then one can write code that s information. –For example,
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
UNIT-V The MVC architecture and Struts Framework.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
Comp 248 Introduction to Programming Chapter 4 - Defining Classes Part A Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
PHP : Hypertext Preprocessor
1 Chapter 6 – Creating Web Forms and Validating User Input spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
Tutorial 14 Working with Forms and Regular Expressions.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
Tutorial 11 Using and Writing Visual Basic for Applications Code
CSCI 6962: Server-side Design and Programming Validation Tools in Java Server Faces.
Java: Chapter 1 Computer Systems Computer Programming II.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
Chapter 7 Java Server Pages. Objectives Explain how the separation of concerns principle applies to JSP Describe the operation and life-cycle of a JSP.
Introduction to JavaServer Pages (JSP) Slides from Dr. Mark Llewellyn.
Java Server Pages Lecture July Java Server Pages Java Server Pages (JSPs) provide a way to separate the generation of dynamic content (java)
Java Users Group Charleston, SC June 25, 2008 Introduction to Grails by Jason McDonald.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
By: Saurabh Dixit.  Grails is a full stack framework and attempts to solve as many pieces of the web development puzzle through the core technology and.
Chapter 8 Cookies And Security JavaScript, Third Edition.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Regular Expression (continue) and Cookies. Quick Review What letter values would be included for the following variable, which will be used for validation.
Grails Mansura Habiba 13 november Introduction What is Grails? Runs on the Java Virtual Machine Used Java like dynamic language Groovy Inspired.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Enhancing Forms with OLE Fields, Hyperlinks, and Subforms – Project 5.
Java server pages. A JSP file basically contains HTML, but with embedded JSP tags with snippets of Java code inside them. A JSP file basically contains.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Storing and Retrieving Data
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
OOSSE Week 8 JSP models Format of lecture: Assignment context JSP models JSPs calling other JSPs i.e. breaking up work Parameter passing JSPs with Add.
JSP BASICS AND ARCHITECTURE. Goals of JSP Simplify Creation of dynamic pages. Separate Dynamic and Static content.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Programming with Microsoft Visual Basic th Edition
Peyman Dodangeh Sharif University of Technology Spring 2014.
Struts Framework Day-2 Ashok Chakravarti. DataSource Usage Sample Struts-config.xml …
1 Java Server Pages A Java Server Page is a file consisting of HTML or XML markup into which special tags and code blocks are inserted When the page is.
XP Tutorial 7 New Perspectives on JavaScript, Comprehensive 1 Working with Forms and Regular Expressions Validating a Web Form with JavaScript.
Data transfer and type conversion One of the common tasks of the web application domain was moving and converting data from string-based HTTP to the various.
Java Programming: Advanced Topics 1 Building Web Applications Chapter 13.
Text INTRODUCTION TO ASP.NET. InterComm Campaign Guidelines CONFIDENTIAL Simply Server side language Simplified page development model Modular, well-factored,
SDJ INFOSOFT PVT. LTD. 2 BROWSERBROWSER JSP JavaBean DB Req Res Application Layer Enterprise server/Data Sources.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
World Wide Web has been created to share the text document across the world. In static web pages the requesting user has no ability to interact with the.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Part VI: Mapping URLs.
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Form Submission And Saving Data To.
A variable is a name for a value stored in memory.
J2EE Lecture 7: Spring – Spring MVC
Struts 2 Validation Framework
Introduction to Scripting
More Selections BIS1523 – Lecture 9.
Phil Tayco Slide version 1.0 Created Oct 2, 2017
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Presentation transcript:

By: Saurabh Dixit

 Groovy server pages  Taglibs  Validators in grails

 View pages with the extension gsp, gsp stands for groovy server page  All default groovy tags along with custom tags defined in the tag lib can be accessed in these pages.

 Tags can be created inside taglib folder in grails: class WidgetsTagLib { static namespace = “appTags" ApplicationContext applicationContext /** * Extends the regular grails pagination */ def paginate = { attrs -> // DO some operation } Tags inside taglib can be accessed on the GSP pages through the name space: appsTags: Name space defined in the tag lib Paginate: Method in the file

 Declaring Constraints:  Within a domain class constraints are defined with the constraints property that is assigned a code block: class User { String login String password String Integer age static constraints = { … }

 You then use method calls that match the property name for which the constraint applies in combination with named parameters to specify constraints: class User {... static constraints = { login size: 5..15, blank: false, unique: true password size: 5..15, blank: false true, blank: false age min: 18 }

 In that example we've declared that the login property must be between 5 and 15 characters long, it cannot be blank and must be unique. We've also applied other constraints to the password, and age properties.  By default, all domain class properties are not nullable (i.e. they have an implicit nullable:false constraint).

 A complete reference for the available constraints can be found in the Quick Reference section under the Constraints heading. class User {... static constraints = { // this Date object is created when the constraints are evaluated, not // each time an instance of the User class is validated. birthDate max: new Date() } Custom validator: class Response { … static constraints = { survey blank: false answer blank: false, validator: { val, obj -> val in obj.survey.answers } }

 Validating Constraints:  Call the validate method to validate a domain class instance : def user = new User(params) if (user.validate()) { // do something with user } else { user.errors.allErrors.each { println it }  The errors property on domain classes is an instance of the Spring Errors interface. The Errors interface provides methods to navigate the validation errors and also retrieve the original values.

 Validation Phases:  Within Grails there are two phases of validation, the first one being data binding which occurs when you bind request parameters onto an instance such as: def user = new User(params)

 At this point you may already have errors in the errors property due to type conversion (such as converting Strings to Dates). You can check these and obtain the original input value using the Errors API: if (user.hasErrors()) { if (user.errors.hasFieldErrors("login")) { println user.errors.getFieldError("login").rejectedValue }

 The second phase of validation happens when you call validate or save. This is when Grails will validate the bound values againts the constraints you defined.  For example, by default the save method calls validate before executing, allowing you to write code like: if (user.save()) { return user } else { user.errors.allErrors.each { println it }

 Importing Constraints:  Grails 2 introduced an alternative approach to sharing constraints that allows you to import a set of constraints from one class into another.  Let's say you have a domain class like so: class User { String firstName String lastName String passwordHash static constraints = { firstName blank: false, nullable: false lastName blank: false, nullable: false passwordHash blank: false, nullable: false }

 You then want to create a command object, UserCommand, that shares some of the properties of the domain class and the corresponding constraints. You do this with the importFrom() method: class UserCommand { String firstName String lastName String password String confirmPassword static constraints = { importFrom User password blank: false, nullable: false confirmPassword blank: false, nullable: false }

 If you want more control over which constraints are imported, use the include and exclude arguments.  Both of these accept a list of simple or regular expression strings that are matched against the property names in the source constraints.

 So for example, if you only wanted to import the 'lastName' constraint you would use: … static constraints = { importFrom User, include: ["lastName"] … }  or if you wanted all constraints that ended with 'Name': … static constraints = { importFrom User, include: [/.*Name/] … }

 Validation on the Client:  Displaying Errors: ▪ Typically if you get a validation error you redirect back to the view for rendering. Once there you need some way of displaying errors. ▪ Grails supports a rich set of tags for dealing with errors. ▪ To render the errors as a list you can use renderErrors:

 If you need more control you can use hasErrors and eachError: ${err}

 Applying Validation to Other Classes:  Domain classes and command objects support validation by default.  Other classes may be made validateable by defining the static constraints property in the class (as described above) and then telling the framework about them.  It is important that the application register the validateable classes with the framework. Simply defining the constraints property is not sufficient.

 The Validateable Annotation:  Classes which define the static constraints property and are annotated can be made validateable by the framework.  Consider this example: // src/groovy/com/mycompany/myapp/User.groovy package com.mycompany.myapp import class User {... static constraints = { login size: 5..15, blank: false, unique: true password size: 5..15, blank: false true, blank: false age min: 18 }