- 浏览: 2553133 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Grails(9)Guide Book Chapter 7 The Web Layer Web Flow
7.5 Web Flow
Grails supports the creation of web flows built on the Spring Web Flow project.
To install a plugin
>grails install-plugin webflow
7.6 Filters
Although Grails controllers support fine gained interceptors. There are only really useful when applied to a few controllers and become difficult to manage with larger applications. Filters on the other hand can be applied across a whole group of controllers, a URI space or to a specific action.
7.7 Ajax
<g:javascript library="jquery" />
7.7.1.1 Remoting Linking
<g:remoteLink action="delete" id="1">Delete Book</g:remoteLink>
<g:remoteLink update="[success: 'message', failure: 'error']"
action="delete" id="1">
Delete Book
</g:remoteLink>
7.7.1.3 Remote Form Submission
<g:formRemote url="[controller: 'book', action: 'delete']"
update="[success: 'message', failure: 'error']">
<input type="hidden" name="id" value="1" />
<input type="submit" value="Delete Book" />
</g:formRemote>
Data Centric Ajax with JSON
import grails.converters.JSON
def showBook(){
def b = Book.get(params.id)
render b as JSON
}
Data Centric Ajax with XML
import grails.converters.XML
def showBook(){
def b = Book.get(params.id)
render b as XML
}
Responding to both Ajax and non-Ajax requests
It's straightforward to have the same Grails controller action handle both Ajax and non-Ajax requests. Grails adds the isXhr() method to HttpServletRequest which can be used to identify Ajax requests.
7.8 Content Negotiation
8. Validation
8.1 Declaring Constraints
class User {
String login
String password
String email
Integer age
static constraints = {
login size: 5..15, blank: false, unique: true
password size: 5..1, blank: false
email email: true, blank: false
age min: 18
}
}
8.2 Validating Constraints
def user = new User(params)
if(user.validate()){
…snip...
}else{
user.errors.allErrors.each {
println it
}
}
Validation Phases
def user = new User(params)
if(user.hasErrors()){
if(user.errors.hasFieldErrors("login")) {
println user.errors.getFieldError("login").rejectedValue
}
}
By default the save method calls validate before executing, allowing us to write code like this:
if(user.save()){
return user
}else{
user.errors.allErrors.each {
println it
}
}
Importing Constraints
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
}
}
class UserCommand {
String firstName
String lastName
String password
String confirmPassword
static constraints = {
importFrom User
password blank: false, nullable: false
confirmPassword blank: false, nullable: false
}
}
8.4 Validation on the Client
Displaying Errors
<g:renderErrors bean="${user}" /> // this can render the errors list.
<g:hasErrors bean="${user}">
<ul>
<g:eachError var="err" bean="${user}">
<li>${err}</li>
</g:eachError>
</ul>
</g:hasErrors>
Highlighting Errors
<div class=‘value ${hasErrors(bean:user, field: 'login', 'errors')}’>
<input type="text" name="login" value="${fieldValue(bean:user, field:'login'}" />
</div>
If there is error, there should be errors CSS in the div.
Also, we restore the value input by the user using the fieldValue tag
8.5 Validation and Internationalization
8.6 Applying Validation to Other Classes
References:
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/theWebLayer.html#webflow
http://grails.org/doc/latest/guide/validation.html
7.5 Web Flow
Grails supports the creation of web flows built on the Spring Web Flow project.
To install a plugin
>grails install-plugin webflow
7.6 Filters
Although Grails controllers support fine gained interceptors. There are only really useful when applied to a few controllers and become difficult to manage with larger applications. Filters on the other hand can be applied across a whole group of controllers, a URI space or to a specific action.
7.7 Ajax
<g:javascript library="jquery" />
7.7.1.1 Remoting Linking
<g:remoteLink action="delete" id="1">Delete Book</g:remoteLink>
<g:remoteLink update="[success: 'message', failure: 'error']"
action="delete" id="1">
Delete Book
</g:remoteLink>
7.7.1.3 Remote Form Submission
<g:formRemote url="[controller: 'book', action: 'delete']"
update="[success: 'message', failure: 'error']">
<input type="hidden" name="id" value="1" />
<input type="submit" value="Delete Book" />
</g:formRemote>
Data Centric Ajax with JSON
import grails.converters.JSON
def showBook(){
def b = Book.get(params.id)
render b as JSON
}
Data Centric Ajax with XML
import grails.converters.XML
def showBook(){
def b = Book.get(params.id)
render b as XML
}
Responding to both Ajax and non-Ajax requests
It's straightforward to have the same Grails controller action handle both Ajax and non-Ajax requests. Grails adds the isXhr() method to HttpServletRequest which can be used to identify Ajax requests.
7.8 Content Negotiation
8. Validation
8.1 Declaring Constraints
class User {
String login
String password
String email
Integer age
static constraints = {
login size: 5..15, blank: false, unique: true
password size: 5..1, blank: false
email email: true, blank: false
age min: 18
}
}
8.2 Validating Constraints
def user = new User(params)
if(user.validate()){
…snip...
}else{
user.errors.allErrors.each {
println it
}
}
Validation Phases
def user = new User(params)
if(user.hasErrors()){
if(user.errors.hasFieldErrors("login")) {
println user.errors.getFieldError("login").rejectedValue
}
}
By default the save method calls validate before executing, allowing us to write code like this:
if(user.save()){
return user
}else{
user.errors.allErrors.each {
println it
}
}
Importing Constraints
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
}
}
class UserCommand {
String firstName
String lastName
String password
String confirmPassword
static constraints = {
importFrom User
password blank: false, nullable: false
confirmPassword blank: false, nullable: false
}
}
8.4 Validation on the Client
Displaying Errors
<g:renderErrors bean="${user}" /> // this can render the errors list.
<g:hasErrors bean="${user}">
<ul>
<g:eachError var="err" bean="${user}">
<li>${err}</li>
</g:eachError>
</ul>
</g:hasErrors>
Highlighting Errors
<div class=‘value ${hasErrors(bean:user, field: 'login', 'errors')}’>
<input type="text" name="login" value="${fieldValue(bean:user, field:'login'}" />
</div>
If there is error, there should be errors CSS in the div.
Also, we restore the value input by the user using the fieldValue tag
8.5 Validation and Internationalization
8.6 Applying Validation to Other Classes
References:
http://grails.org/doc/latest/guide/index.html
http://grails.org/doc/latest/guide/theWebLayer.html#webflow
http://grails.org/doc/latest/guide/validation.html
发表评论
-
NodeJS12 and Zlib
2020-04-01 07:44 476NodeJS12 and Zlib It works as ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 337Traefik 2020(1)Introduction and ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 385Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 479NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 424Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 337Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 248GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 452GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 328GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 314Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 319Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 294Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
2020-02-19 01:17 312Serverless with NodeJS and Tenc ... -
NodeJS MySQL Library and npmjs
2020-02-07 06:21 290NodeJS MySQL Library and npmjs ... -
Python Library 2019(1)requests and aiohttp
2019-12-18 01:12 261Python Library 2019(1)requests ... -
NodeJS Installation 2019
2019-10-20 02:57 574NodeJS Installation 2019 Insta ... -
Monitor Tool 2019(2)Monit on Multiple Instances and Email Alerts
2019-10-18 10:57 266Monitor Tool 2019(2)Monit on Mu ... -
Sqlite Database 2019(1)Sqlite3 Installation and Docker phpsqliteadmin
2019-09-05 11:24 368Sqlite Database 2019(1)Sqlite3 ... -
Supervisor 2019(2)Ubuntu and Multiple Services
2019-08-19 10:53 371Supervisor 2019(2)Ubuntu and Mu ...
相关推荐
《Grails 2 的终极指南》是一本深入探讨Grails框架精髓的专业书籍,该书以英文撰写,旨在为读者提供全面、深入的Grails框架学习资料。Grails框架基于Groovy语言,是一种高度动态、敏捷的Java应用开发框架,它简化了...
Grails Cometed. Bin 1 The best web push
Grails Cometed. Bin 3 The best web push
Grails Cometed. Bin 1 The best web push
《The Definitive Guide to Grails 2》是Grails框架深入学习的重要参考资料,由业界专家撰写,旨在为开发者提供全面、详尽的Grails 2技术指导。这本书结合了理论与实践,不仅介绍了Grails的基本概念,还涵盖了高级...
- **实战技巧**:包括 GORM (Groovy Object Relational Mapping) 的使用、如何在 Grails 中实现 Ajax 功能、处理遗留数据库的方法、利用遗留框架以及如何在 Grails 中使用 WebFlow。 - **高效编程系列**:涵盖使用 ...
### Grails快速开发Web应用:知识点详解 #### Grails框架概览 Grails是一个基于Groovy语言构建的开源MVC(Model-View-Controller)Web开发框架,以其高效的开发速度和简洁的代码著称。其核心优势在于: 1. **快速...
**Grails CometD:最佳Web推送技术** 在现代Web开发中,实时通信是不可或缺的一部分,它使得用户可以即时获取服务器端的数据更新,无需频繁刷新页面。Grails CometD框架就是为了实现这种实时交互而设计的。本文将...
Grails 采用了约定优于配置的原则,简化了 Web 应用程序的开发过程,使得开发者能够快速构建出功能完备且易于维护的 Web 应用。 ### Groovy 语言 Groovy 是一种运行于 Java 平台上的动态编程语言,它融合了 Python...
《Grails企业Web应用开发与部署》 在现代软件开发领域,Grails作为一个基于Groovy语言的开源Web应用框架,以其高效、灵活和强大的特性深受开发者喜爱。它提供了丰富的插件系统,使得企业级Web应用的开发变得快速而...
《The Definitive Guide to Grails 2》是关于Grails框架的一本权威指南,它为读者提供了深入理解和使用Grails 2开发Web应用程序所需的知识。Grails是一种基于Groovy语言的开源全栈式Web应用框架,它借鉴了Ruby on ...
《Grails技术精解与Web开发实践11-20章》是一本专注于Grails框架的深度解析书籍,尤其适合初学者和希望提升Grails开发技能的IT从业者。Grails是一种基于Groovy语言的开源Web应用框架,它以其高效、灵活和强大的特性...
《Grails技术精解与Web开发实践2-10章》是针对Grails框架的一份珍贵资源,适合初学者及有经验的开发者深入理解并掌握Grails技术。这本书的章节涵盖了从基础到进阶的多个方面,旨在帮助读者全面了解和运用Grails进行...
自己买的书,然后用扫描机扫描的,整个文件太大了,不能一次性上传上来,所以拆成3个part。 我自己学grails很想看这本书,结果网上没有,就自己去买了,然后共享给需要的人。 如果有什么问题请联系我下架。
自己买的书,然后用扫描机扫描的,整个文件太大了,不能一次性上传上来,所以拆成3个part。...我自己学grails很想看这本书,结果网上没有,就自己去买了,然后共享给需要的人。 如果有什么问题请联系我下架。
### Grails快速开发Web应用程序知识点解析 #### 一、Grails框架概述 - **定义**:Grails是一个基于Groovy语言构建的开源Model-View-Controller (MVC) Web开发框架。它旨在简化Web应用程序的开发流程,提高开发效率...
《The definitive Guide To Grails学习笔记》是一份深入探讨Grails框架的重要资源,它源于经典书籍《The Definitive Guide to Grails》的精华总结。Grails是一种基于Groovy语言的开源Web应用框架,旨在提高开发效率...
《使用 Grails 快速开发 Web 应用程序》 Grails,一个基于Groovy动态语言的开源MVC框架,为Web开发提供了高效且简洁的解决方案。自2007年发布以来,Grails以其快速开发能力,降低了Web应用的复杂性,吸引了众多...
Grails企业web应用开发与部署.pdf 很好的资源