command-objects

Grails command object data binding

隐身守侯 提交于 2020-01-09 06:20:20
问题 Grails has very good support for binding request parameters to a domain object and it's associations. This largely relies on detecting request parameters that end with .id and automatically loading those from the database. However, it's not clear how to populate the associations of a command object. Take the following example: class ProductCommand { String name Collection<AttributeTypeCommand> attributeTypes ProductTypeCommand productType } This object has a single-ended association with

Grails 2.3.1 Command Object Data Binding at Controller Parameters

女生的网名这么多〃 提交于 2019-12-25 05:09:33
问题 I recently upgrade from grails 2.2 to 2.3.1. My controller used to bind data to an command object at controller parameters. After I upgraded to 2.3.1, the binding seems not working and have '[Fatal Error] :-1:-1: Premature end of file.' output to console. it works fine at 2.2 like this def home(ACommand cmd) {} after upgrading, it outputs 'Premature end of file' before it goes to the action and skip the action method and going to home.gsp view directly. I also tried new an instance inside the

Grails: How do you unit test a command object with a service injected into it

隐身守侯 提交于 2019-12-21 17:34:15
问题 I am trying to test a Controller that has a Command object with data binding. The Command Object has a Service injected into it. But When I try test the command object the injected service method is never found as it is never "injected" Is there a way to mock a service inside a command object? Test method void testLoginPasswordInvalid() { mockRequest.method = 'POST' mockDomain(User, [new User(login:"freddy", password:"realpassword")]) mockLogging(UserService) // userService mocked MockUtils

bind date to command object in Grails

痴心易碎 提交于 2019-12-17 14:46:46
问题 I have a date (as a string) being submitted. I'd like to map this to a command object. I have looked around quite a bit and found no great resource on how to do this mapping within a command object to a real date. If I were to do this in the controller itself I could just do the following, however this doesn't allow me to easily map into my command object. def endDate = params.date('endDate', 'MM/dd/yyyy') For my command object, the closest I've been able to get is to override the getter and

Grails command object temporary field validation

江枫思渺然 提交于 2019-12-12 02:33:56
问题 I have a user registration form where the fields are validated using command object. One of the fields is a checkbox, which must checked before proceeding the registration, and it isn't saved to the domain object. This checkbox has a corresponding Boolean field in the command object. When checkbox is not checked, a validation error is thrown from a custom validator. The problem is, that this error is not propagated in the <g:renderErrors bean="${command}" as="xml"/> block (the validator is

How to bind data to a command object that has a nested property? (non domain object)

ε祈祈猫儿з 提交于 2019-12-08 04:37:48
问题 I am trying to bind some data to an object that is part of a command object. The object stays null when trying to use it. Probably i am not giving the correct data in the gsp but i have no clue what am i doing wrong! I would expect that when i submit a form with a field name 'book.title' this would get mapped into the command object.. but this fails.. The title stays [null] Whenever i change the command object and form to use String title as property it works.. // the form that submits the

grails validate nested command object not working

我的梦境 提交于 2019-12-07 03:39:56
问题 I'm using grails 2.2.1 and attempting to validate a nested command structure. Here is a simplified version of my command objects: @Validateable class SurveyCommand { SectionCommand useful SectionCommand recommend SurveyCommand() { useful = new SectionCommand( question: 'Did you find this useful?', isRequired: true) recommend = new SectionCommand( question: 'Would you recommend to someone else?', isRequired: false) } } @Validateable class SectionCommand { String question String answer boolean

grails validate nested command object not working

我怕爱的太早我们不能终老 提交于 2019-12-05 08:17:25
I'm using grails 2.2.1 and attempting to validate a nested command structure. Here is a simplified version of my command objects: @Validateable class SurveyCommand { SectionCommand useful SectionCommand recommend SurveyCommand() { useful = new SectionCommand( question: 'Did you find this useful?', isRequired: true) recommend = new SectionCommand( question: 'Would you recommend to someone else?', isRequired: false) } } @Validateable class SectionCommand { String question String answer boolean isRequired static constraints = { answer(validator: answerNotBlank, nullable: true) } static

How to add constraints on inherited properties in a grails domain sub-class

最后都变了- 提交于 2019-11-30 10:57:35
Here's what I'd like to do: class A { String string static constraints = { string(maxSize:100) } } class B extends A { static constraints = { string(url:true) } } So class A should have some constraints and B should have the same plus additional constraints on the same property. I couldn't get that to work though and I can imagine that it would clash with the Table-per-Hierarchy concept. So I tried to work around that problem by introducing a Command object with class B's constraints which can be validated in the constructor of class B. However it seems that Command objects can only be used

How to add constraints on inherited properties in a grails domain sub-class

半城伤御伤魂 提交于 2019-11-29 16:21:45
问题 Here's what I'd like to do: class A { String string static constraints = { string(maxSize:100) } } class B extends A { static constraints = { string(url:true) } } So class A should have some constraints and B should have the same plus additional constraints on the same property. I couldn't get that to work though and I can imagine that it would clash with the Table-per-Hierarchy concept. So I tried to work around that problem by introducing a Command object with class B's constraints which