惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
V2EX
Y
Y Combinator Blog
博客园_首页
V
Visual Studio Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
阮一峰的网络日志
阮一峰的网络日志
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
B
Blog
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
WordPress大学
WordPress大学
L
LangChain Blog
爱范儿
爱范儿
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
C
Check Point Blog
博客园 - 聂微东
云风的 BLOG
云风的 BLOG
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Help Net Security

博客园 - 页面载入出错

Grails指南摘要-403-生命周期 Grails指南摘要-402-logging Grails指南摘要-401-Controller中设置默认Action Grails指南摘要-307-测试领域类 Grails指南摘要-306-嵌入式对象 Grails指南摘要-305-扩展和继承 Grails指南摘要-304-对象关系 Grails指南摘要-303-自定义对象映射 Grails指南摘要-302-瞬时属性 Grails指南摘要-301-属性验证 20130527-jQuery in actin-看代码说事-ch01 20130518-Grails In Action-5、控制应用程序流(04小节) 20130517-Grails In Action-5、控制应用程序流(02小节) 20130517-Grails In Action-5、控制应用程序流(01小节) 20130517-Grails In Action-4、让模型工作(06小节) 20130516-Grails In Action-4、让模型工作(05小节) 20130516-Grails In Action-4、让模型工作(04小节) 20130516-Grails In Action-4、让模型工作(03小节) 20130516-Grails In Action-4、让模型工作(02小节)
20130518-Grails In Action-5、控制应用程序流(03小节)
页面载入出错 · 2013-05-19 · via 博客园 - 页面载入出错

数据绑定

应用场景:一个表单更新多个领域对象,在这个应用中,注册一个用户需要更新user和profile两个对象,我们新建一个register表单

grails-app\views\user\register.gsp

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <title>Register New User</title>
 5         <meta name="layout" content="main"/>
 6         <style>
 7             dd {
 8                 text-align: left;
 9                 margin-left: 80px;
10                 margin-top: 5px;
11             }
12         </style>
13     </head>
14     
15     <body>
16         <h1>Register New User</h1>
17         <g:hasErrors>
18             <div class="errors">
19                <g:renderErrors bean="${user}" as="list" />
20             </div>
21         </g:hasErrors>
22         <g:form action="register">
23             <dl>
24                 <dt>User Id</dt><dd><g:textField name="userId" value="${user?.userId}"/></dd>
25                 <dt>Password</dt><dd><g:passwordField name="password" value="${user?.password}"/></dd>
26                 <dt>Full Name</dt><dd><g:textField name="profile.fullName" value="${user?.profile?.fullName}"/></dd>
27                 <dt>Bio</dt><dd><g:textArea name="profile.bio" value="${user?.profile?.bio}"/></dd>
28                 <dt>Email</dt>
29                 <dd>
30                     <g:textField name="profile.email" value="${user?.profile?.email}"/>
31                     <g:hasErrors bean="${user}" field="profile.email">
32                         <g:eachError bean="${user}" field="profile.email">
33                             <p style="color: red;"><g:message error="${it}"/></p>
34                         </g:eachError>
35                     </g:hasErrors>
36                 </dd>
37                 <dt><g:submitButton name="register" value="Register"/></dt>
38             </dl>
39         </g:form>
40     </body>
41 </html>

表单提交给register这个action,在UserController中新建一个actioon

grails-app\controllers\com\grailsinaction\UserController.groovy

 1     def register = {
 2         def user = new User(params)
 3         if (user.validate()) {
 4             user.save()
 5             flash.message = "Successfully Created User"
 6             redirect(uri: '/')
 7         } else {
 8             flash.message = "Error Registering User"
 9             return [ user: user ]
10         }
11     }