Grails not binding Enumerations coming from forms

View: New views
4 Messages — Rating Filter:   Alert me  

Grails not binding Enumerations coming from forms

by cinar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

Grails is not binding the Enumerations coming from the forms. Most likely I'm doing something wrong, any ideas?

Here are my domain objects:

class User {
   static hasMany = [userRoles: UserRole]
}

enum UserRole {
   ADMIN,
   GUEST
}

Here is the select box on the form:

<g:select name="userRoles" from="${UserRole.values()}"
                        value="${fieldValue(bean: userInstance, field: 'userRoles')}"
                        valueMessagePrefix="userRole"
                        size="5" multiple="true" />

The select box gets rendered correctly, however when I submit the form, the userRoles property of User domain object does not get the values.

Here is my controller:

def userInstance = User(params)

Thanks in advance for your help.

-onur







Re: Grails not binding Enumerations coming from forms

by Hubert Chang :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

<g:select name="userRoles" from="${UserRole?.values()}"
                        value="${userInstance?.userRoles'}"
                        size="5" multiple="true" />

cinar wrote:
Hi,

Grails is not binding the Enumerations coming from the forms. Most likely I'm doing something wrong, any ideas?

Here are my domain objects:

class User {
   static hasMany = [userRoles: UserRole]
}

enum UserRole {
   ADMIN,
   GUEST
}

Here is the select box on the form:

<g:select name="userRoles" from="${UserRole.values()}"
                        value="${fieldValue(bean: userInstance, field: 'userRoles')}"
                        valueMessagePrefix="userRole"
                        size="5" multiple="true" />

The select box gets rendered correctly, however when I submit the form, the userRoles property of User domain object does not get the values.

Here is my controller:

def userInstance = User(params)

Thanks in advance for your help.

-onur






Re: Grails not binding Enumerations coming from forms

by cinar :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Rendering of enumeration is already working fine. The problem is that, when the form get submitted, the "userRoles" fields does not get correctly binded to the User.userRoles property.

I added a few log lines for debugging, and I am seeing that the params.userRoles is an array of Enumeration names. However after I do new User(params), all properties gets assigned except the userRoles property.

Does anyone have a working example with Enumerations?



<g:select name="userRoles" from="${UserRole?.values()}"
                        value="${userInstance?.userRoles'}"
                        size="5" multiple="true" />

cinar wrote:
Hi,

Grails is not binding the Enumerations coming from the forms. Most likely I'm doing something wrong, any ideas?

Here are my domain objects:

class User {
   static hasMany = [userRoles: UserRole]
}

enum UserRole {
   ADMIN,
   GUEST
}

Here is the select box on the form:

<g:select name="userRoles" from="${UserRole.values()}"
                        value="${fieldValue(bean: userInstance, field: 'userRoles')}"
                        valueMessagePrefix="userRole"
                        size="5" multiple="true" />

The select box gets rendered correctly, however when I submit the form, the userRoles property of User domain object does not get the values.

Here is my controller:

def userInstance = User(params)

Thanks in advance for your help.

-onur







Re: Grails not binding Enumerations coming from forms

by John Fletcher-12 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Currently working for me:

<g:select id="sitio" name="sitio"
                            from="${Sitio.values()}"
                            optionKey="${{it.name()}}"
                            value="${usuario.sitio}"/>

John

2009/11/4 cinar <onur.cinar@...>

Does anyone have a working example with Enumerations?