0

zk popup menu EventListener onOpen fire twice

asked 2015-07-17 13:17:53 +0800

javiut gravatar image javiut flag of Venezuela, Bolivarian Republic of
90 1 5

updated 2015-07-20 16:41:03 +0800

I have a Hbox like this which is attached to a Menu PopUp.

final Hbox box = ....................
final Popup pop = this.createPopUp(box);
final EventListener<Event> onOpen = new EventListener<Event>()
{
public void onEvent(final Event event)
    {
    popup.removeEventListener(Events.ON_OPEN,this);     
    event.stopPropagation();                    
    log.info("OnOpen");             
    popup.addEventListener(Events.ON_OPEN,this);
    return;
 }
 };
popup.addEventListener(Events.ON_OPEN,onOpen);
box.setPopup(pop);
pop.setParent(box);

That's ok i have set a onOpen event listener to my popup everything works like a expected the problem is when i click in the Hbox the onOpen event is firing twice i mean i can see 2 OnOpen message this is worring because i have some DB operations in that method my question is how avoid the eventListener onOpen only fired twice..

Another weird fact is the first time Hbox is clicked only one onOpen is call but from the second time the onopen method is called twice always.

My more specific code

ZUL.

<listcell>
<div align='center'>
   <hbox onCreate='myController.onCreateHBox(self);'>
    <label value="Actions"/>                                        
   </hbox>                              
</div>
</listcell>

In Java

public void onCreateHBox(final Hbox box)
{
 final Popup pop = new Popup();
 pop.appendChild(new Label("Bon Jovi"));
 final EventListener<Event> onOpen = new EventListener<Event>(){public void onEvent(final Event event){log.info("called"); return;}};
 pop.addEventListener(Events.ON_OPEN,onOpen);
 pop.setWidth("200px");                                     
 box.setPopup(pop);
 pop.setParent(box);                    
}

What i see and i dont understand and i think is a bug suppose you have a popup open and you change the browser window or pick another popup maybe windows popup and your zk popup closes that's ok but i see when my popup closes their ONOPEN event is called why is onOpen not on_close this is some confussing...

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-07-20 13:59:07 +0800

Darksu gravatar image Darksu
1991 1 4

Hello javiut,

Since that did not work then there probably is something in the code that affects it. Could you please upload a more complete sample?

Furthermore a second option would be to add a Boolean value that will prevent any code from executing twice (if always two events are created).

Best Regards,

Darksu

link publish delete flag offensive edit

Comments

I post my code darksu thanks a lot

javiut ( 2015-07-20 14:44:16 +0800 )edit

i also try to create a custom implementation of PopUp with a validator to call the method or not but i set the flag the 1 time the method is call and clean it when the method is finish but when the event is call always is false the flag and do not works neither.

javiut ( 2015-07-20 14:45:27 +0800 )edit

i think is a bug the 1 time only time is called the 2 time and further is called twice always..

javiut ( 2015-07-20 16:07:48 +0800 )edit

Darksu i have the solution was because the onOpen event was fired when popup was close() and that's was the problem... thanks men...

javiut ( 2015-07-20 17:04:57 +0800 )edit
0

answered 2015-07-17 14:06:19 +0800

Darksu gravatar image Darksu
1991 1 4

Hello javiut,

Why not remove the event listener once its entered (triggered), and re-add it once the operation is finished.

Best Regards,

Darksu

link publish delete flag offensive edit

Comments

mmmmmmmm seems good idea seems the hbox components fires something like a popUp.open() and it's fire twice i will try your approach.

javiut ( 2015-07-17 14:20:14 +0800 )edit

hello darksu do not work neither.. see my edited code. stil firing twice.

javiut ( 2015-07-20 12:16:52 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
1 follower

RSS

Stats

Asked: 2015-07-17 13:17:53 +0800

Seen: 36 times

Last updated: Jul 20 '15

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More