|
Hello, I am new to Grails development and have been having issues with <g:select> when it is used for a multi-select list. In my form users can select between 1 to 6 options in a multi-select list box. They can then go back to an edit view to make changes. The form successfully saves all the options that were selected, but if more than one option was selected the listbox won't display that any were selected in the edit view. If only one option was selected however, it is displayed in the edit view. Could someone please give me some idea of how to fix it so that all selected options are displayed in edit view? (Running Grails 2.0.3) Here is my <g:select> code in the GSP: .... <g:select selected="true" multiple="true" name="securityGroup" from="${[ 'Mainframe', 'Finance', 'EDI', 'Item Master', 'Risk Management', 'Telecomm' ]}" value="${MFAdminInstance?.securityGroup}"/> .... Thanks, Jon ********************************************************************************************* This email message and any attachments is for use only by the named addressee(s) and may contain confidential, privileged and/or proprietary information. If you have received this message in error, please immediately notify the sender and delete and destroy the message and all copies. All unauthorized direct or indirect use or disclosure of this message is strictly prohibited. No right to confidentiality or privilege is waived or lost by any error in transmission. ********************************************************************************************* --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
I can't say for certain what's going on, you don't show the controller code, how the posted form (or GET) params are being bound to MFAdminInstance, what MFAdminInstance.securityGroup is (a string property of a domain class), etc.
So I'm speculating here. My guess is that the list of Strings you're using in the from="" attribute of your g:select tag is not of the same type as what is returned from MFAdminInstance?.securityGroup. Do you get a String back from MFAdminInstance?.securityGroup? I think what g:select does for the multi-case is to loop over the from list, extract a key (in your case via toString) and then see if each of those keys is "in" the value list using a groovy "contains". For your code that would look like a bunch of "contains" expressions that, in your case, would translate to something like... MFAdminInstance?.securityGroup.contains('Mainframe') MFAdminInstance?.securityGroup.contains('Finance') MFAdminInstance?.securityGroup.contains('EDI') etc. If MFAdminInstance?.securityGroup.contains isn't a list, I don't think you're going to get the behavior that you want. And if it's not a list of Strings, you're not going to get matches from the "contains" expression since your "keys" are strings. At least that's my best guess at the moment. The g:select is a bit of a beast, IMO, particularly for the "multi" use-case. I find myself skywalkering (using the source) more than I feel I should have to for g:select. - Gary On Jun 27, 2012, at 11:16 AM, [hidden email] wrote: > > Hello, I am new to Grails development and have been having issues with > <g:select> when it is used for a multi-select list. In my form users can > select between 1 to 6 options in a multi-select list box. They can then go > back to an edit view to make changes. The form successfully saves all the > options that were selected, but if more than one option was selected the > listbox won't display that any were selected in the edit view. If only one > option was selected however, it is displayed in the edit view. > > Could someone please give me some idea of how to fix it so that all > selected options are displayed in edit view? (Running Grails 2.0.3) > > Here is my <g:select> code in the GSP: > > .... > <g:select selected="true" multiple="true" name="securityGroup" from="${[ > 'Mainframe', 'Finance', 'EDI', 'Item Master', 'Risk Management', 'Telecomm' > ]}" value="${MFAdminInstance?.securityGroup}"/> > .... > > Thanks, > > Jon > > > ********************************************************************************************* > This email message and any attachments is for use only by the named addressee(s) and may contain confidential, privileged and/or proprietary information. If you have received this message in error, please immediately notify the sender and delete and destroy the message and all copies. All unauthorized direct or indirect use or disclosure of this message is strictly prohibited. No right to confidentiality or privilege is waived or lost by any error in transmission. > ********************************************************************************************* > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Gary,
I will definitely look into what you are describing and see what I can come up with. Thanks so much for the help! Jon From: Gary Affonso <[hidden email]> To: [hidden email], Date: 06/28/2012 03:51 PM Subject: Re: [grails-user] Issues with <g:select> I can't say for certain what's going on, you don't show the controller code, how the posted form (or GET) params are being bound to MFAdminInstance, what MFAdminInstance.securityGroup is (a string property of a domain class), etc. So I'm speculating here. My guess is that the list of Strings you're using in the from="" attribute of your g:select tag is not of the same type as what is returned from MFAdminInstance?.securityGroup. Do you get a String back from MFAdminInstance?.securityGroup? I think what g:select does for the multi-case is to loop over the from list, extract a key (in your case via toString) and then see if each of those keys is "in" the value list using a groovy "contains". For your code that would look like a bunch of "contains" expressions that, in your case, would translate to something like... MFAdminInstance?.securityGroup.contains('Mainframe') MFAdminInstance?.securityGroup.contains('Finance') MFAdminInstance?.securityGroup.contains('EDI') etc. If MFAdminInstance?.securityGroup.contains isn't a list, I don't think you're going to get the behavior that you want. And if it's not a list of Strings, you're not going to get matches from the "contains" expression since your "keys" are strings. At least that's my best guess at the moment. The g:select is a bit of a beast, IMO, particularly for the "multi" use-case. I find myself skywalkering (using the source) more than I feel I should have to for g:select. - Gary On Jun 27, 2012, at 11:16 AM, [hidden email] wrote: > > Hello, I am new to Grails development and have been having issues with > <g:select> when it is used for a multi-select list. In my form users can > select between 1 to 6 options in a multi-select list box. They can then go > back to an edit view to make changes. The form successfully saves all the > options that were selected, but if more than one option was selected the > listbox won't display that any were selected in the edit view. If only one > option was selected however, it is displayed in the edit view. > > Could someone please give me some idea of how to fix it so that all > selected options are displayed in edit view? (Running Grails 2.0.3) > > Here is my <g:select> code in the GSP: > > .... > <g:select selected="true" multiple="true" name="securityGroup" from="${[ > 'Mainframe', 'Finance', 'EDI', 'Item Master', 'Risk Management', > ]}" value="${MFAdminInstance?.securityGroup}"/> > .... > > Thanks, > > Jon > > > ********************************************************************************************* > This email message and any attachments is for use only by the named addressee(s) and may contain confidential, privileged and/or proprietary information. If you have received this message in error, please immediately notify the sender and delete and destroy the message and all copies. All unauthorized direct or indirect use or disclosure of this message is strictly prohibited. No right to confidentiality or privilege is waived or lost by any error in transmission. > ********************************************************************************************* > > --------------------------------------------------------------------- > To unsubscribe from this list, please visit: > > http://xircles.codehaus.org/manage_email > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email ********************************************************************************************* This email message and any attachments is for use only by the named addressee(s) and may contain confidential, privileged and/or proprietary information. If you have received this message in error, please immediately notify the sender and delete and destroy the message and all copies. All unauthorized direct or indirect use or disclosure of this message is strictly prohibited. No right to confidentiality or privilege is waived or lost by any error in transmission. ********************************************************************************************* --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
| Powered by Nabble | Edit this page |
