Questions tagged [command-objects]

Command Objects are a feature of the Grails web framework, refering to special classes that declare constraints used to validate its instances.

Resources

Official docs

Related tags:

90 questions
25
votes
4 answers

Grails command object data binding

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…
Dónal
  • 185,044
  • 174
  • 569
  • 824
23
votes
4 answers

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

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…
11
votes
1 answer

Where should Grails Command objects be placed in the project structure?

I have a class called LoginCommand in domain/my/package/name class LoginCommand { String emailAddress String password } My question is why is a table be auto generated in my database for a ***Command object in grails? Are these command…
benstpierre
  • 32,833
  • 51
  • 177
  • 288
10
votes
2 answers

Grails: nested command objects

In my grails app I have an outer command object that contains a list of other command objects: public class OuterCommand { List innerCommands = ListUtils.lazyList([], FactoryUtils.instantiateFactory(InnerCommand)) } class…
Dónal
  • 185,044
  • 174
  • 569
  • 824
8
votes
3 answers

bind date to command object in Grails

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…
Scott
  • 16,711
  • 14
  • 75
  • 120
7
votes
3 answers

grails validate nested command object not working

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() { …
Chris Montgomery
  • 2,344
  • 2
  • 19
  • 30
6
votes
2 answers

How do you properly bind a list of objects into a Grails command?

I'm trying to figure out how to deserialize and validate nested objects in JSON request into a Grails 2.1.1 command object. Currently I have a command object in my controller that has a few basic properties and then list of domain objects, protected…
James McMahon
  • 48,506
  • 64
  • 207
  • 283
5
votes
2 answers

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

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…
Daxon
  • 1,397
  • 2
  • 21
  • 38
4
votes
1 answer

Grails 2.5.0 controller command object binding after accessing request.JSON in a filter

In a Grails 2.5.0 controller action method, it seems like the properties in the HTTP JSON body will not be used for command object binding if request.JSON has been accessed in a filter. Why is that? It doesn't make any sense to me. Is there any way…
XDR
  • 4,070
  • 3
  • 30
  • 54
4
votes
1 answer

Data binding not working if index is greater than 255

I am working on a application using grails version 2.3.9. There I am rendering a list with check-box. User can select any row(s) and submit the page. And at server side I am using command object to bind the data. My command…
MKB
  • 7,587
  • 9
  • 45
  • 71
3
votes
0 answers

grails @BindUsing command Object

I am using grails 2.5.5 and the problem is when I'm using a command Object, I want to change the format of the data I get with the @BindUsing annotation. @Validatable class FooCommand extends BarCommand{ @BindUsing({obj, source -> return…
miThom
  • 373
  • 2
  • 11
3
votes
3 answers

Get ahold of session in command object in Grails

How can I get the session from within a command object? I have tried: import org.springframework.security.context.SecurityContextHolder as SCH class MyCommand { def session = RCH.currentRequestAttributes().getSession() } This throws…
RyanLynch
  • 2,987
  • 3
  • 35
  • 48
3
votes
1 answer

Grails Command Objects and Pagination

I have been updating some of my controllers to use command objects and started down the road of making a PaginateCommand for other command objects to extend. class PaginateCommand { String sort String order Integer max Integer…
kjackson
  • 65
  • 7
3
votes
1 answer

Grails adding version to command object causes id and version from params not to be bound

I apologize if I'm missing something really obvious here but I've been pulling my hair out with this issue. I have a command object: class MyCommand { Long id String value } I bind to this in my controller: public update(MyCommand myCmd)…
Conor Power
  • 686
  • 1
  • 6
  • 17
3
votes
1 answer

Can Grails Command Objects have variable number of parameters?

We are using Command Objects with Grails controllers in Grails 2.0.1. This is fantastic feature and has led to very nice, concise controllers with fully validated parameters. I have a case where there is a web service call implemented in a…
Rich Sadowsky
  • 966
  • 1
  • 12
  • 22
1
2 3 4 5 6