Skip to main content
Inspiring
February 21, 2010
Answered

(new) flash cdfrid with multiple choices

  • February 21, 2010
  • 2 replies
  • 1275 views

My cfgrid allows the user to select several options.  What I need to know is how to capture those selections.  Here's the grid code:

<cfgrid name='art_grid' format='flash' selectOnLode='no' selectMode='edit' query='GetArticles'>

     <cfgridcolumn name='ArticleIndex' select='yes' values='1' type='boolean' display='yes'>

     <cfgridcolumn name='ArticleName' select='no'>

</cfgrid>

I've tried a cfselect and a cfset (both with selectedItem and selectedIndex); both receiving the same error:  You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.

I created a structure to hold the responses and then tried to populate it with:

<cfloop collection='#art_grid.selectedItem# item='i'>

     <cfset ArtStruct='#art_grid.selectedItem.ArticleName#'>

</cfloop>

What should I use instead?  (Yes, I googled the error message and this is where I got the structure idea.)

    This topic has been closed for replies.
    Correct answer BKBK

    Strange things happen when you submit a form containing a grid. See the documentation, under the section Returning cfgrid data to the action page

    HTML format:

    If you leave the checkboxes unchecked, form.art_grid.ArticleIndex and form.art_grid.ArticleName will return simple values. If you check one or more checkboxes, Coldfusion will generate the following arrays:

    form.art_grid.ArticleIndex 

    form.art_grid.ArticleName 

    form.art_grid.original.ArticleIndex 

    form.art_grid.original.ArticleName

    form.art_grid.rowstatus.action

    Flash format:

    The flash format will generate the above arrays, whether or not the checkboxes are checked. When the checkboxes are unchecked, the arrays are empty.

    Run the following test code, with and without checked checkboxes

    <cfif isDefined("form.fieldnames")>
    <cfdump var="#form#">
    </cfif>

    <cfform>
    <cfgrid name='art_grid' format='flash' selectOnLode='no' selectMode='edit' query='GetArticles'>

         <cfgridcolumn name='ArticleIndex' select='yes' values='1' type='boolean' display='yes'>

         <cfgridcolumn name='ArticleName' select='no'>

    </cfgrid>
    <cfinput type="submit" name="sbmt" value="send">
    </cfform>


    2 replies

    BKBK
    Community Expert
    BKBKCommunity ExpertCorrect answer
    Community Expert
    February 23, 2010

    Strange things happen when you submit a form containing a grid. See the documentation, under the section Returning cfgrid data to the action page

    HTML format:

    If you leave the checkboxes unchecked, form.art_grid.ArticleIndex and form.art_grid.ArticleName will return simple values. If you check one or more checkboxes, Coldfusion will generate the following arrays:

    form.art_grid.ArticleIndex 

    form.art_grid.ArticleName 

    form.art_grid.original.ArticleIndex 

    form.art_grid.original.ArticleName

    form.art_grid.rowstatus.action

    Flash format:

    The flash format will generate the above arrays, whether or not the checkboxes are checked. When the checkboxes are unchecked, the arrays are empty.

    Run the following test code, with and without checked checkboxes

    <cfif isDefined("form.fieldnames")>
    <cfdump var="#form#">
    </cfif>

    <cfform>
    <cfgrid name='art_grid' format='flash' selectOnLode='no' selectMode='edit' query='GetArticles'>

         <cfgridcolumn name='ArticleIndex' select='yes' values='1' type='boolean' display='yes'>

         <cfgridcolumn name='ArticleName' select='no'>

    </cfgrid>
    <cfinput type="submit" name="sbmt" value="send">
    </cfform>


    sockerdadAuthor
    Inspiring
    February 23, 2010

    That did the trick - I had to move the evaluation of the grid selections to the next module and all went well.  I took care of the option of various number of choices by dumping the grid into an array and using ArrayLen to check the number of choices.

    I wish I could get grid choices to remain in the same order as they are on the grid (rather than dumping them in alphabetical order), but that isn't worth chasing.

    There are a couple of remaining oddities, however.  When I move to the next page on the Submit button, if the user has failed to make a choice, I refer them back to the previous page to complete that selection.  The grid is then gone, and they have to refresh the page to see the grid again - and losing the other fields they have entered.  But - a small price to pay to learn to do it right the first time!

    Second oddity is that the grid has the first entry checked on initial display - although it seems not to be "really" checked because if I don't click anything else, the grid array comes up empty.  I have not been able to get rid of this because the grid is Flash, not HTML.  Minor detail, definitely not a show stopper.

    Inspiring
    February 21, 2010

    What do you get if you do a dump of form.art_grid?  That might give you an idea of how to reference the values...

    --

    Adam

    sockerdadAuthor
    Inspiring
    February 22, 2010

    Kind of a weird dump using <cfdump var='#art_grid#'>    (The form.art_grid was undefined...)

    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" height="320" marginBottom="0" marginLeft="0" marginRight="0" marginTop="0" rsl="/CFIDE/scripts/cfform.swc" width="580"> <mx:Script><![CDATA[ import mx.core.UIObject; var errorpopup; function compareNumeric(a,b) { var a1 = parseFloat(a); var b1 = parseFloat(b); if( a1.toString() == 'NaN' ) a1 = 0; if( b1.toString() == 'NaN' ) b1 = 0; if( a1 < b1 ) return -1; if( a1 == b1 ) return 0; return 1; } function compareCurrency(a,b) { var a1 = new mx.formatters.NumberBase().parseNumberString( a ); var b1 = new mx.formatters.NumberBase().parseNumberString( b ); var a1 = parseFloat(a1); var b1 = parseFloat(b1); if( a1.toString() == 'NaN' ) a1 = 0; if( b1.toString() == 'NaN' ) b1 = 0; if( a1 < b1 ) return -1; if( a1 == b1 ) return 0; return 1; } function compareTextNoCase(a,b) { var a1 = a.toLowerCase(); var b1 = b.toLowerCase(); if( a1 < b1 ) return -1; if( a1 == b1 ) return 0; return 1; } var __art_grid_cacheid = "0"; var __art_grid_editedFields = new Object(); var __art_grid; ]]></mx:Script> <mx:Model id="CFForm_1"> <__CFGRID__CFForm_1__art_grid>{__art_grid}</__CFGRID__CFForm_1__art_grid> </mx:Model> <mx:Style> .artgridHeader { textAlign: Left; } </mx:Style> <mx:Form heightFlex="1" marginBottom="0" marginLeft="0" marginRight="0" marginTop="0" widthFlex="1"> <mx:DataGrid editable="true" fontFamily="tahoma" fontSize="12" hGridLines="true" headerStyle="artgridHeader" height="320" id="art_grid" initialize="GridData.initGrid(true, __art_grid_cacheid, art_grid, this, 'CFForm_1', '__CFGRID__CFForm_1__art_grid', remoteObject_art_grid)" textAlign="left" vGridLines="true" width="580"> <mx:columns> <mx:Array> <mx:DataGridColumn columnName="CFGRIDROWINDEX" editable="false" headerText="" resizable="false" sortable="true" width="0"/> <mx:DataGridColumn cellRenderer="{CheckCellRenderer}" columnName="ArticleIndex" editable="false" headerText="Select" resizable="true" sortable="true" width="50"/> <mx:DataGridColumn columnName="ArticleName" editable="false" headerText="Article" resizable="true" sortable="true" width="530"/> </mx:Array> </mx:columns> </mx:DataGrid> </mx:Form> <mx:RemoteObject concurrency="multiple" endpoint="@ContextRoot()/CFFormGateway/" id="remoteObject_art_grid" showBusyCursor="true" source="coldfusion.flash.adapter.CFFormAdapter"/> </mx:Application>

    Interesting, but I don't understand it.

    Inspiring
    February 22, 2010

    Um... hang on.

    Are you wanting to capture these values before or after the user submits the form?  BEcause those are two completely different kettles of fish.

    --

    Adam