问题标签 [grails-validation]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1290 浏览

grails - Grails 错误代码

我试图从与 Grails 中的域对象交互时引发的异常中确定错误代码是什么。

我有一个具有一些字段验证的数据库,其中一个验证是特定列必须是唯一的。根据文档,它会给出一个错误代码className.propertyName.uniquehttp://grails.org/doc/latest/ref/Constraints/unique.html)。当我将控制器包装在 try catch 块中时。我可以捕获各种验证异常:

如何访问错误代码?我想做点什么If the Error Code = className1.propertyName2.unique,然后回应propertyName2 is not unique

当我进行保存操作时,我确实将“failOnError:true”设置为参数。

谢谢!

0 投票
3 回答
207 浏览

ruby-on-rails - 需要当前密码才能设置新密码

我希望用户在编辑他们的个人资料时输入他们当前的密码。

这就是我的用户模型的样子:

我的控制器参数:

用户表单部分:

但是我的堆栈级别太深了,它进入了一个验证循环。

我究竟做错了什么?

0 投票
1 回答
435 浏览

grails - Grails文件上传:视图渲染时如何设置输入文件的值

我有一个upload从视图上的表单接收文件的操作。上传文件时完成验证。

如果文件无效,则再次显示视图,输入type="file"值应指向上传失败的文件。

这似乎不起作用:(视图中的代码)

这是呈现给用户的:

有任何想法吗?

0 投票
1 回答
52 浏览

hibernate - Grails validation over own domain

I'm using Grails 2.4.2 and have a class Contract which has many InvoiceRecipient's. The InvoiceRecipients class has an attribute invoiceType which has 2 possible values, 'O' for the invoice-original and 'C' for an invoice-copy. As you could imagine, only one record with type 'O' is allowed for the InvoiceRecipients for one contract.

If I try to implement it as in the following snipplet, the VM runs into a StackOverflow.

Another approach I tried was a service method which iterates through the recipients array of the contract to count the records with invoiceType 'O' or I tried to do a select count through InvoiceRecipient.countByContractAndInvoiceType() to determine the number of 'O's in the contract->invoiceRecipients relation in the controller.

In both last cases, Hibernate generates an update statement for my current InvoiceRecipient record, which I try to validate. And even if the validation of the current InvoiceRecipient fails and I populate the errors-object of the instance, the record is already updated (without problems, because the constraint is not coded into the class and throws no error in "save".) And I have the logical-wrong records in the database.

0 投票
1 回答
192 浏览

swing - Griffon 从控制器更新模型和视图

您好,我是 Griffon 框架的新手,我想在我的应用程序中添加登录功能。以下是我的模型、视图和控制器:

SignInModel.groovy

}

SignInView.groovy

类签到视图 {

}

SignInController.groovy

类登录控制器 {

}

如果用户名和密码为空并显示错误消息,我想更新我的登录视图。我能够在我的模型中收到错误消息,但我的视图没有更新,所以请帮助我。

@注意:我添加了 griffon 验证插件

0 投票
1 回答
109 浏览

grails - 防止 Grails 2.4.4 接受无效日期

我的一位同事在 Grails 2.4.4 中编写了一个应用程序(我知道,它已经过时了)。该应用程序的一个问题是您可以输入 2/31/2015 之类的日期,它会被接受为有效日期,并将在您的域对象中显示为 2015 年 3 月 3 日。

有什么简单的方法可以使用 grails 来防止这种情况发生吗?或者我们是否必须依赖客户端验证这个特定属性?

谢谢。

0 投票
2 回答
78 浏览

grails - 在自定义验证器中使用标准验证器进行 Grails 验证

我想在自定义验证器中使用标准验证器。

我想确保人口和产品字段组合只有在错误的情况下才是唯一的model_type.has_range_options。我尝试了以下方法,但它不起作用:

还有什么我可以尝试的吗?

0 投票
1 回答
282 浏览

spock - Grails 2.2.4:瞬态属性:为什么自定义验证器被调用两次?

给定一个具有瞬态属性的简单域,例如:

还有一个针对域约束的简单单元测试,如下:

当我运行这个规范时,它只是为了验证非瞬态属性sensei,发生了两件意想不到的事情:

  1. 两个自定义验证器都被调用;
  2. 不仅名称的自定义验证器被调用,而且实际上被调用了两次

一探究竟:

因此,我只想知道的是:

考虑到该测试仅验证属性sensei

  • 为什么调用两个自定义验证器?
  • 另外,为什么瞬态属性名称的自定义验证器被调用两次?

示例项目@github

==== 编辑:

一件有趣的事:

奇怪的是,每当我在名称的自定义验证器上放置一个 rejectValue 时,例如:

自定义验证器只被调用一次。

但是,不应该根本不调用名称的自定义验证器

0 投票
0 回答
73 浏览

grails - grails 命令对象验证不一致

我有以下带有约束的命令对象:

在控制器内以下列方式启动对象:

当我最初部署验证不起作用时, validate() 总是返回 true 而 hasError() 返回 null。

当我们使用 nginx 时,如果我在 RefundCommand 文件中进行任何更改,那么在自动编译验证之后就会开始工作。

这可能是什么原因?

我们将 grails-2.2.2 与 nginx 服务器一起使用。

0 投票
1 回答
410 浏览

grails - 在 Grails 中,我无法覆盖默认错误消息

但仍然没有运气。我仍然收到默认错误消息,即“类 [package_name] 的属性 [用户名] 不能为空。我使用的是 Grails 3.0.8