How to hide a drop-down list (generated by a reference)?

orion_mjcl

New member
Hi everybody. I have a question. I'm developing a grails app where I have many users. As I'm using Spring Security I can obtain a reference to the logged user. Here's my domain classes:

class Recepcion {
String nombre
Date fechaDeRecepcion
String numeroDeSacos
BigDecimal peso
String placaDeAutomovil
String numeroDeTornaguia
Date fechaDeTornaguia

static belongsTo = [usuario: Usuario, proveedor: Proveedor]

static constraints = {
...
}
}

class RecepcionDeCobre extends Recepcion{
Integer loteCu
transient springSecurityService

def beforeInsert = {
def c = RecepcionDeCobre.createCriteria()
def results = c {
projections {
max('loteCu')
}}
def maxLote = results.get(0)?: 0
this.loteCu = maxLote + 1
this.usuario = springSecurityService.getCurrentUser() <--obtaining logged user reference
}

static constraints = {
loteCu( display: false, nullable: true )
}
}

class Usuario extends SecUser{ // SecUser was generated with a Spring Security command
String nombre
String apellido
String email
String puntoDeTrabajo

static constraints = {
...
}
}

The create view for RecepcionDeCobre in the field Usuario show a list containing all the registered users. How can I hide this list? As I can get the logged user this seems redundant and unnecessary. I deleted the code for this list and its label directly in its GSP but when I want to register new data it produces an error message that says "Usuario cannot be null" what is perfectly correct. Again, how can I hide this list preventing this error and having a reference to the logged user?

Thanks in advance.
 

robmorning

New member
I think your going to set it as nullable in the constraints .. I'm assuming your doing a validate() in the create closure - this will look for a non existent user as you have removed it from your gsp and the 'beforeInsert' wont populate it till you do the database insetr which is after the validation ...
 
Top