-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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. }
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
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.
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
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 !! } }
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?
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
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
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 ... */ }
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.
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,
Asked: 2009-11-25 09:53:56 +0800
Seen: 827 times
Last updated: Nov 26 '09