0

Events, autowire and forwar functions issue

asked 2009-11-25 09:53:56 +0800

n4rk0 gravatar image n4rk0
120 3

Hi all,

I'm working with events and autowired functions, and I'm having some troubles. My first problem was solved using this thread

Combobox setSelectedIndex


But, when I thought that everything was ok, I found another problem. My onClicks events on that page always calls onEvent method, but my onChange events on a combobox don't. I have autowired functions on that page that are not executed. I tried to remove the onEvent event with stop propagation method and with remove event listenet, but I don't work. I tried with forward method with the same results.

This is my code :



public void doAfterCompose(Component window){     ... 
     cmbTipoDocumento.addEventListener("onInitRenderLater", this);
     ...
}


public void onEvent(Event e){
   ... // This executes on onClick events(buttons), but not onChange events (comboboxes)
}

public void onChange$cmbTipoDocumento(Event event){
   ... //Autowired methods are not executed.
}

public void onClickbtnEditar(Event event){
   ... //Forward methods are not executed.

}



Any suggestions? Thanks for your time.

n4rk0

delete flag offensive retag edit

12 Replies

Sort by ยป oldest newest

answered 2009-11-25 10:37:13 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Download the sources of my sampleApp as Eclipse projects. here.

best
Stephan

If you will take the time than look at the using of the BaseCtrl.java

link publish delete flag offensive edit

answered 2009-11-25 13:31:41 +0800

n4rk0 gravatar image n4rk0
120 3

I have some network limitations at office, could you paste your class here, please please? :D I remember that I read your BaseCtrl class in another thread, but I can't find it now.
I tried doing what I want with e.getTarget() instanceof Component, but e.getTarget() always return the window, so I can't do that in that way neither. I don't want to do a complex code solving the problem, I'm not going to maintain it. My idea was to filter the targets, first by component, and then by ID.

Thanks for your time.
n4rk0

PS. The subject has a typo error, could some admin change it? Thanks.

link publish delete flag offensive edit

answered 2009-11-25 14:37:23 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-11-25 14:44:06 +0800

There are older codes for a complete module here.
included the BaseCtrl (use="").

In the next update of the sample app there is a similar BaseController as a BaseGenericForwarderComposer as used for spring-managed creation (with apply="")
it's nearly exact the same code.

call it with the doOnCreateCommon(branchListWindow); out from the onCreateEvent of the controller.

best
Stephan

link publish delete flag offensive edit

answered 2009-11-25 14:43:10 +0800

n4rk0 gravatar image n4rk0
120 3

updated 2009-11-25 14:45:32 +0800

I solved my problem without using your BaseCtrl class, Stephan. I don't know if you do it in the same way that I did. This is my code.


<zk:combobox id="cmbTipoDocumento" forward="onChange=winEmisionContrante.onChangecmbTipoDocumento" />
<zk:button id="btnEditar" forward="onClick=winEmisionContrante.onClickbtnEditar"/>
<zk:button id="btnGuardar" forward="onClick=winEmisionContrante.onClickbtnGuardar"/>

public void onEvent(Event event){
                                String strEventName = event.getName();
		if(strEventName.equals("onChangecmbTipoDocumento")){
			... // All what I need !!
		}else if(strEventName.equals("onClickbtnEditar")){
			... // All what I need !!
		}else if(strEventName.equals("onClickbtnGuardar")){
                                                ... // All what I need !!
                                }
}


With event.getName() I can get the event forward name. With debugg and luck I noticed that ! xP Thanks for your reply Stephan, but I still want to see your class, could you paste the code, please?
Thanks for your time.

n4rk0

EDIT. Stephan, that was the thread ! Thanks ! I was writing the reply while you were posting yours xD.

link publish delete flag offensive edit

answered 2009-11-25 14:48:52 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-11-25 14:52:15 +0800

saving lag
wow. double saving lags :-)

PS: only a hint. Some guys, me too, prefer small zul-files and do the code in the controllers. Is yours a prototyp?

link publish delete flag offensive edit

answered 2009-11-25 15:00:00 +0800

n4rk0 gravatar image n4rk0
120 3

No, it isn't. In this case, I'm working in an outsourcing ( Is that correct? :] ) and I'm not going to maintain the code, and people at this company don't have experience in ZK developing, so the java code has to be as simple as possible, and my not elegant solution ( xP ) looks like a "configuration". What do you think ?
Thanks for your time.

n4rk0

link publish delete flag offensive edit

answered 2009-11-25 15:18:42 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

Get the sample codes as eclipse project that i offer.
If i understand it right, the backend is from your customer and you do a new frontend.?

best
Stephan
sge(at)forsthaus(dot)de

link publish delete flag offensive edit

answered 2009-11-25 16:02:21 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

updated 2009-11-25 16:03:13 +0800

Sorry to join the party late, but to elaborate on Stephan's comment about the next iteration of his example, I never use the "use" attribute. I use "apply." You can compare your technique to this for the GenericForwardComposer-based stuff:

public void onChange$cmbTipoDocumento(Event event)
{
			... // All what I need !!
}


public void onClick$btnEditar(Event event)
{
			... // All what I need !!
}


public void onClick$btnGuardar(Event event)
{
			... // All what I need !!
}

The parameters can be a more specific subclass of Event, too.

As Stephan mentioned, it's nearly exactly the same code that ends up doing the work, but more elegant. I invariably need to do stuff to setup the composer, so I override doAfterCompose(...) like this:

pubic void doAfterCompose(Event evt)
{
    super.doAfterCompose(evt) ;   // it autowires variables and events

     /*
         ....  all the stuff I need to do on init ...
     */
}

link publish delete flag offensive edit

answered 2009-11-25 16:09:56 +0800

n4rk0 gravatar image n4rk0
120 3

updated 2009-11-25 16:11:30 +0800

Hi caclark,

I usually do it in that way, but as you can see in this thread, if I use event$component and addEventListener("onInitRenderLater", this); this autowired methods are not executed, so the complete solutions doesn't work. This is the reason for this solution. Any other suggestion?
Thanks for your time.

EDIT.Stephan, I do both, frontend and backend, but in future I will not mantein the code.

link publish delete flag offensive edit

answered 2009-11-26 05:51:39 +0800

fmcypriano gravatar image fmcypriano
612 1 7
http://felipecypriano.com...

updated 2009-11-26 06:08:27 +0800

Hi n4rk0,

If I'm correct this is all because you want to setSelectedIndex in a combobox, right?

Based on the code show in the thread Combox setSelectedIndex, I've updated the code to this:

<window id="win" apply="MyController">
  <combobox id="years"/>
</window>

public class MyController extends GenericAutowireComposer {
  private Combobox years;

  public onCreate$win() {
    years.setModel(new ListModelList(Arrays.asList("2007", "2008", "2009")));    
  }

  public void onInitRenderLater$years(Event e) {
    years.setSelectedIndex(2);
  }
}

It works for me, and you don't need to override onEvent method.


Cheers,

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: 2009-11-25 09:53:56 +0800

Seen: 827 times

Last updated: Nov 26 '09

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