0

im using grails 2.4.4. im new so I have a noob question probably I have domain class like this:

class E_PreguntaFrecuente {

static embedded=['perfiles','secciones','subsecciones']

String pregunta
String respuesta
Integer orden

static hasMany=[perfiles:E_Perfil,secciones:E_Seccion,subsecciones:E_Subseccion]

static constraints = {
    pregunta blank:false
    respuesta blank:false
    orden blank:false
    subsecciones nullable: true
}

}

I want the hasMany list of subsecciones to be nullable... how can I do that? I've tried what you see in the code; subsecciones nullable:true and some other variations like putting (nullable:true) but none of them seem to work, it keeps saying that the subsecciones list is required.

edit

I have no errors, just want to have a non required list...

here is an image of what I mean, i dont know if it can be nullable at save.. but i cant even pass the form part..

enter image description here

juanmeza
  • 163
  • 1
  • 12
  • What does it mean `none of them seem to work`? Do you have an error on saving a certain object? Please add more informations. – lifeisfoo Sep 01 '15 at 17:32
  • I mean that it keeps saying its required... I'll edit.. ty – juanmeza Sep 01 '15 at 17:37
  • See this http://stackoverflow.com/a/5389126/3340702 and this http://stackoverflow.com/a/6943763/3340702 – lifeisfoo Sep 01 '15 at 17:48
  • so, all your `hasMany` collections are also `embedded`? no further questions... – injecteer Sep 01 '15 at 18:06
  • yes, all of them are also embedded – juanmeza Sep 01 '15 at 18:07
  • @lifeisfoo I tried those posts before posting my own, they did not work for me.. the list is still required – juanmeza Sep 01 '15 at 18:09
  • Why must they be embedded? – Emmanuel Rosa Sep 01 '15 at 18:51
  • Why don't you just add the list property? Or add initial default value like `[]`? Could you post your controller action code? – lifeisfoo Sep 01 '15 at 19:17
  • @EmmanuelRosa they are embedded because i want the whole json, im using mongoDB database... and i want to use it in another web application – juanmeza Sep 01 '15 at 20:40
  • @lifeisfoo I added the list property like this: Set subsecciones = [], and also like this: List subsecciones = []... they work but i cant make it nullable... (i also have the hasMany even tho i declare as list as well) – juanmeza Sep 01 '15 at 20:41
  • Could you paste error messagees from your domain object? You can see them after a failed `save()`, using `yourObj.errors.allErrors.each { println it }` in the controller action – lifeisfoo Sep 01 '15 at 21:12
  • @lifeisfoo i have no errors, i can save succesfully, i just HAVE to save the subsecciones list... and i want it to be optional – juanmeza Sep 01 '15 at 21:23
  • If you don't have any errors during the save of an object with a null `subsecciones` field, I can't understand where is the problem. But wait, when you say "it keeps saying its required", who is the subject of the action? Are you talking about a message in the web page that appears when you try to save the object? Could you post your view data and a screenshot? – lifeisfoo Sep 01 '15 at 21:32
  • @lifeisfoo yes! its a web form problem, but i think that is defined in the domain am i wrong?(im sorry im new in grails) then i execute a "generate-all" command...i updated the question with an image! thank you... PS, i dont know what you mean by "view data" – juanmeza Sep 02 '15 at 01:19
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88523/discussion-between-juanmeza-and-lifeisfoo). – juanmeza Sep 02 '15 at 01:37

1 Answers1

0

so found a workaround, or maybe thats how its done, idk, im new in grails... this is the generated tag in the _form.gsp file:

<g:select name="subsecciones" from="${com.test.jwm.E_Subseccion.list()}" multiple="multiple" optionKey="id" size="5" required="" value="${e_PreguntaFrecuenteInstance?.subsecciones*.id}" class="many-to-many"/>

by removing the required="" attribute, it works as expected...

I just dont know how to configure the domain class so it gets generated that way... for other string variables it works with just nullable:true in the domain class... but well.. at least i found a workaround..

if anyone knows a better way, pls share

juanmeza
  • 163
  • 1
  • 12