-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi
I'm simply wondering if there is any way to attach a PhaseListener to a specific component? It's a little tedious to handle "everything" within the same PhaseListener.
since ZK 8 you can add additional phase listeners via BinderCtrl#addPhaseListener(PhaseListener)
If you want to make it component specific you can pass the component as a constructor arg e.g.:
@Init
public void init(
@ContextParam(ContextType.BINDER) BinderCtrl binderCtrl,
@ContextParam(ContextType.VIEW) Component view ) {
binderCtrl.addPhaseListener(new MyPhaseListener(view));
}
Based on the information you provided so far I can't tell if that's helpful for your case. Since I almost never had to add a PhaseListener myself I could imagine there's an alternative that doesn't require changing the internals.
The idea was to "intercept" the binding process to create the bound object (myObject) on demand but I don't know if this is possible.
<textbox value="@bind(vm.myObject.myProperty)"/>
Then in the PhaseListener do proper setup of "myObject" in prePhase:
public void prePhase(Phase phase, BindContext bindContext) {
//if phase is INITIAL_BIND(not sure which phase it would be in this case) then create myObject etc..
}
Another idea is to intercept the validation phase to get immediate single field validation without executing the command, just like "save before command" but without executing the commmand if validation fails. This is to avoid numerous error messages at once.
http://books.zkoss.org/zk-mvvm-book/8.0/data_binding/validator.html
Asked: 2018-11-26 19:24:30 +0800
Seen: 7 times
Last updated: Nov 29 '18