You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by Paul Hastings <pa...@gmail.com> on 2013/11/07 10:37:36 UTC

spark Datagrid GridItemEditorEvent firing twice

i have a spark datagrid that is firing off two 
GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE events for a single edit. no 
popups or custom item editors are involved & it seems to happen with both the 
user tabbing out or using the enter key to save the edited data. the datagrid 
has only the one editable column.

everything's working as planned just that it's doubled up (i can see two rows in 
the transaction table for every singe edit on the datagrid).

is listening for GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE the correct 
approach? some magic i should be doing to the event or datagrid? i vaguely 
recall there maybe being something on alex's blog about preventing extra events 
but i'm not finding anything related (or likely not searching w/the right keyword).

thanks.

if it matters:

adding the event listener:
workOrdersDG.addEventListener(GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE,onEditSave,false);

event handler (sorry for the formatting mess):
protected function onEditSave(event:GridItemEditorEvent):void {
  errMsg.text="";
  var item:Object=(event.currentTarget.dataProvider).getItemAt(event.rowIndex);
  var mData:String=item.meterData;				
  if (mData !="" && isNaN(Number(mData))) {
 
(event.currentTarget.dataProvider).getItemAt(event.rowIndex)[event.column.dataField]="";
   (event.currentTarget.dataProvider).getItemAt(event.rowIndex)["usage"]="0";
   workOrdersDG.selectedIndex=event.rowIndex;
   errMsg.text="Meter data must be numeric."
} else {
  if(Number(item.meterData) >=item.lastCollectedData) {
 
(event.currentTarget.dataProvider).getItemAt(event.rowIndex)["usage"]=Number(item.meterData)-item.lastCollectedData;
  // send back to server
  assetService.updateWalkOrderMeterData(item.id,item.meterData,userID);	
  } else
   errMsg.text="Current meter data must be greater than last collected data."
}

Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Paul Hastings <pa...@gmail.com>.
On 11/8/2013 1:21 PM, Alex Harui wrote:
> The fix we'll implement will probably just keep a flag about whether we've
> already seen the event or not.  Can you implement a similar flag in your
> handler?

yeah it was the among the very first things i tried. but i guess i flubbed the 
logic & it got lost in the "turbulence" w/the events getting queued for 
remoting, etc. i guess its less "icky" than going back to mx datagrids.

thanks again.


Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Alex Harui <ah...@adobe.com>.
The fix we'll implement will probably just keep a flag about whether we've
already seen the event or not.  Can you implement a similar flag in your
handler?

-Alex

On 11/7/13 9:53 PM, "Paul Hastings" <pa...@gmail.com> wrote:

>On 11/8/2013 11:49 AM, Alex Harui wrote:
>> OK, debugged into it.
>
>thanks.
>
>> There is two, so I'd say it is a bug.  Way back in May I added code to
>
>looking at mx datagrid as a fallback otherwise it could be a show stopper
>for 
>us. first glance seems doable but the datagrid event seems to behave
>differently 
>& i'm maybe not getting the update timing right.
>
>this is a transition (and fallback later) from paper data collection to
>tablet 
>collected data & editing within the datagrid seems like the most
>"natural" way 
>of handling this.
>
>thanks again for taking the time.
>


Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Paul Hastings <pa...@gmail.com>.
On 11/8/2013 11:49 AM, Alex Harui wrote:
> OK, debugged into it.

thanks.

> There is two, so I'd say it is a bug.  Way back in May I added code to

looking at mx datagrid as a fallback otherwise it could be a show stopper for 
us. first glance seems doable but the datagrid event seems to behave differently 
& i'm maybe not getting the update timing right.

this is a transition (and fallback later) from paper data collection to tablet 
collected data & editing within the datagrid seems like the most "natural" way 
of handling this.

thanks again for taking the time.


Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Alex Harui <ah...@adobe.com>.
OK, debugged into it.

There is two, so I'd say it is a bug.  Way back in May I added code to
GridItemEditor.save() to force focus back to the DG so that controls
commit their values.  I thought there was a check to prevent save() from
doing its work twice, but there isn't.  Another event gets dispatched (in
my case from hitting the ENTER key to close the editor).

Seems like we need a flag to determine that save has done its thing.

-Alex

On 11/7/13 7:12 PM, "Paul Hastings" <pa...@gmail.com> wrote:

>On 11/8/2013 6:09 AM, Alex Harui wrote:
>> Is it the same event instance?  Otherwise, try following the code back
>>to
>
>i believe so.
>
>something i forgot to mention that this is a spark datagrid (i guess i
>should 
>compare w/mx datagrid to see what's what).
>
>i've isolated the datagrid off on its own to isolate from potential
>issues 
>w/module, remoting, etc. still shows the issue:
>
>https://dl.dropboxusercontent.com/u/130830/flex/gridEvent.html
>
>click "edit" to start editing, edit the "edit data" column. every time
>that 
>column is updated, two GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE
>events 
>are fired off. same target, event phase, row, column.
>
>source for that is:
>
>https://dl.dropboxusercontent.com/u/130830/flex/gridEvent.zip
>
>i think this is the first time we've used in-line datagrid editing like
>this, so 
>maybe we're doing it wrong? but it follows the examples i've dug up & i
>*think* 
>i gave a grasp of the basic concepts (famous last words).
>
>thanks.
>
>
>
>
>
>


Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Paul Hastings <pa...@gmail.com>.
On 11/8/2013 6:09 AM, Alex Harui wrote:
> Is it the same event instance?  Otherwise, try following the code back to

i believe so.

something i forgot to mention that this is a spark datagrid (i guess i should 
compare w/mx datagrid to see what's what).

i've isolated the datagrid off on its own to isolate from potential issues 
w/module, remoting, etc. still shows the issue:

https://dl.dropboxusercontent.com/u/130830/flex/gridEvent.html

click "edit" to start editing, edit the "edit data" column. every time that 
column is updated, two GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE events 
are fired off. same target, event phase, row, column.

source for that is:

https://dl.dropboxusercontent.com/u/130830/flex/gridEvent.zip

i think this is the first time we've used in-line datagrid editing like this, so 
maybe we're doing it wrong? but it follows the examples i've dug up & i *think* 
i gave a grasp of the basic concepts (famous last words).

thanks.







Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Alex Harui <ah...@adobe.com>.
Is it the same event instance?  Otherwise, try following the code back to
the dispatchEvent call or examine the call stack with line numbers.

On 11/7/13 7:21 AM, "Paul Hastings" <pa...@gmail.com> wrote:

>Either.
>Does it occur only when debugging, or also when running the application?
>
>Maurice
>
>-----Message d'origine-----
>De : Paul Hastings [mailto:paul.hastings@gmail.com]
>Envoyé : jeudi 7 novembre 2013 15:46
>À : Darrell Loverin; users@flex.apache.org
>Objet : Re: spark Datagrid GridItemEditorEvent firing twice
>
>i copied the wrong bits in the previous email, same target but its
>actually
>spark.components.DataGrid (@2ecd2ae1).
>
>rebooting didn't help, except that its now consistently just double
>events.
>
>watching the backend (sql server & coldfusion servers), i can see nothing
>is sent thru until the 2nd GridItemEditorEvent comes round, then 2 remote
>calls are done. even sticking in a timer in the event listener top slow
>things doen between the events, doesn't effect this, both come thru at the
>exact same instance (eg. '2013-11-07 21:29:02' though maybe coldfusion's
>timer isn't detailed enough to pick up sub ms differences, still looks
>same
>to me).
>
>real head scratcher.


RE: spark Datagrid GridItemEditorEvent firing twice

Posted by Paul Hastings <pa...@gmail.com>.
Either.
Does it occur only when debugging, or also when running the application?

Maurice

-----Message d'origine-----
De : Paul Hastings [mailto:paul.hastings@gmail.com]
Envoyé : jeudi 7 novembre 2013 15:46
À : Darrell Loverin; users@flex.apache.org
Objet : Re: spark Datagrid GridItemEditorEvent firing twice

i copied the wrong bits in the previous email, same target but its actually
spark.components.DataGrid (@2ecd2ae1).

rebooting didn't help, except that its now consistently just double events.

watching the backend (sql server & coldfusion servers), i can see nothing
is sent thru until the 2nd GridItemEditorEvent comes round, then 2 remote
calls are done. even sticking in a timer in the event listener top slow
things doen between the events, doesn't effect this, both come thru at the
exact same instance (eg. '2013-11-07 21:29:02' though maybe coldfusion's
timer isn't detailed enough to pick up sub ms differences, still looks same
to me).

real head scratcher.

RE: spark Datagrid GridItemEditorEvent firing twice

Posted by Maurice Amsellem <ma...@systar.com>.
Does it occur only when debugging, or also when running the application?

Maurice 

-----Message d'origine-----
De : Paul Hastings [mailto:paul.hastings@gmail.com] 
Envoyé : jeudi 7 novembre 2013 15:46
À : Darrell Loverin; users@flex.apache.org
Objet : Re: spark Datagrid GridItemEditorEvent firing twice

i copied the wrong bits in the previous email, same target but its actually spark.components.DataGrid (@2ecd2ae1).

rebooting didn't help, except that its now consistently just double events.

watching the backend (sql server & coldfusion servers), i can see nothing is sent thru until the 2nd GridItemEditorEvent comes round, then 2 remote calls are done. even sticking in a timer in the event listener top slow things doen between the events, doesn't effect this, both come thru at the exact same instance (eg. '2013-11-07 21:29:02' though maybe coldfusion's timer isn't detailed enough to pick up sub ms differences, still looks same to me).

real head scratcher.


Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Paul Hastings <pa...@gmail.com>.
i copied the wrong bits in the previous email, same target but its actually 
spark.components.DataGrid (@2ecd2ae1).

rebooting didn't help, except that its now consistently just double events.

watching the backend (sql server & coldfusion servers), i can see nothing is 
sent thru until the 2nd GridItemEditorEvent comes round, then 2 remote calls are 
done. even sticking in a timer in the event listener top slow things doen 
between the events, doesn't effect this, both come thru at the exact same 
instance (eg. '2013-11-07 21:29:02' though maybe coldfusion's timer isn't 
detailed enough to pick up sub ms differences, still looks same to me).

real head scratcher.


Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Paul Hastings <pa...@gmail.com>.
On 11/7/2013 7:39 PM, Darrell Loverin wrote:
> What are the values of the �target and eventPhase fields for each of the two
> save events?

same: spark.events.GridItemEditorEvent (@315ead61) eventPhase: 2

and while debugging just now i caught it throwing GridItemEditorEvent 3 times. 
maybe the compiler and/or FB is drunk? rebooting & trying again.

thanks.



Re: spark Datagrid GridItemEditorEvent firing twice

Posted by Darrell Loverin <da...@gmail.com>.
What are the values of the  target and eventPhase fields for each of the
two save events?



-Darrell Loverin


On Thu, Nov 7, 2013 at 4:37 AM, Paul Hastings <pa...@gmail.com>wrote:

> i have a spark datagrid that is firing off two
> GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE events for a single
> edit. no popups or custom item editors are involved & it seems to happen
> with both the user tabbing out or using the enter key to save the edited
> data. the datagrid has only the one editable column.
>
> everything's working as planned just that it's doubled up (i can see two
> rows in the transaction table for every singe edit on the datagrid).
>
> is listening for GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_SAVE the
> correct approach? some magic i should be doing to the event or datagrid? i
> vaguely recall there maybe being something on alex's blog about preventing
> extra events but i'm not finding anything related (or likely not searching
> w/the right keyword).
>
> thanks.
>
> if it matters:
>
> adding the event listener:
> workOrdersDG.addEventListener(GridItemEditorEvent.GRID_ITEM_
> EDITOR_SESSION_SAVE,onEditSave,false);
>
> event handler (sorry for the formatting mess):
> protected function onEditSave(event:GridItemEditorEvent):void {
>  errMsg.text="";
>  var item:Object=(event.currentTarget.dataProvider).
> getItemAt(event.rowIndex);
>  var mData:String=item.meterData;
>  if (mData !="" && isNaN(Number(mData))) {
>
> (event.currentTarget.dataProvider).getItemAt(event.rowIndex)[event.column.
> dataField]="";
>   (event.currentTarget.dataProvider).getItemAt(event.
> rowIndex)["usage"]="0";
>   workOrdersDG.selectedIndex=event.rowIndex;
>   errMsg.text="Meter data must be numeric."
> } else {
>  if(Number(item.meterData) >=item.lastCollectedData) {
>
> (event.currentTarget.dataProvider).getItemAt(event.
> rowIndex)["usage"]=Number(item.meterData)-item.lastCollectedData;
>  // send back to server
>  assetService.updateWalkOrderMeterData(item.id,item.meterData,userID);
>  } else
>   errMsg.text="Current meter data must be greater than last collected
> data."
> }
>