0

how to reference the element that generates an onClick event in addEventListener

asked 2011-06-23 17:21:30 +0800

vicnetepc gravatar image vicnetepc
96

I have a window requesting a start date
and an end date. Then, processing is performed
in the database as the reporting period.
Thus, the window dynamically create elements
chat-type dial day per store. Each chart contains
a Label (labelGeral) that displays the name of the store.
I created an event for each label through
labelGeral.addEventListener.
The following excerpt shows a portion of the code:

   ResultSet rr;
	    LojaDAO lojaDAO = new LojaDAO();
	    rr= lojaDAO.buscaLojaPorId(idLoja);
	    String nomeLoja="***";
	    if (rr.next())
	   	 nomeLoja=idLoja+" - "+rr.getString("nome");
	     rr.close();
	     
	   DialModel dialmodel = new DialModel();
	   	scale = dialmodel.newScale(0.0, 99.0, -120.0, -300.0, 10.0, 4);//scale's configuration data
	   	scale.setText("%");
	   	scale.newRange(0, 70.9, "#FF0000", 0.83, 0.89);//VERMELHO
	   	scale.newRange(71, 79.9, "#FFFF00", 0.83, 0.89); //AMARELO
	   	scale.newRange(80, 100, "#00DD00", 0.83, 0.89);//VERDE
	   	
	   	scale.setValue(percentual);   
	
	   	chart = new Chart();
       chart.setTitle("Loja "+idLoja);
       chart.setWidth("185");
       chart.setHeight("185");
       chart.setType("dial");
       chart.setThreeD(false);
       chart.setFgAlpha(128);
       chart.setModel(dialmodel);   
       LOJA=idLoja;
      
       lblGeral = new Label();
       lblGeral.setValue(nomeLoja);
       
       
       lblGeral.addEventListener("onClick", new EventListener() {
    	    public void onEvent(Event e) {
    	    	
    	        ss=lblGeral.getValue();
    	    	tabAtividadesRealizadas.setVisible(true);
    	    tabAtividadesRealizadas.setSelected(true);
             int lojaAtual =0;
             String[] og2=null;
             og2 = ss.split("\\ ");
             lojaAtual = Integer.parseInt(og2[0]);
            
    	    try {
				processaAtividadesRealizadas(lojaAtual);
			} catch (WrongValueException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (InterruptedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (ParseException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
    	   }
 
    	 });

But the method processaAtvidadesRealizadas (lojaAtual) only receives the content
lojaAtual the same as the last store processed, since this is the value
labelGeral received the Label, but I want to use the label's value
that was clicked.
How to solve this? How do I use the contents of the label that received
onClick event?
Thank you.

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2011-07-10 22:56:46 +0800

RyanWu gravatar image RyanWu
533 2
about.me/flyworld

ZK have several event type, in your case, the label (lblGeral) listen the "onClick" event, which means you can got some data from the event object.

The event e in "public void onEvent(Event e) {" is a MouseEvent

you can get the lblGeral like following:

MouseEvent evt_click = (MouseEvent) e;
Label clickedLabel = evt_click.getTarget();

API getTarget http://www.zkoss.org/javadoc/latest/zk/org/zkoss/zk/ui/event/Event.html#getTarget()

link publish delete flag offensive edit
Your reply
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

RSS

Stats

Asked: 2011-06-23 17:21:30 +0800

Seen: 168 times

Last updated: Jul 10 '11

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